gpt4 book ai didi

c# - disqus API 缺少必需的参数 : grant_type

转载 作者:行者123 更新时间:2023-11-30 17:59:27 27 4
gpt4 key购买 nike

我正在尝试通过 disqus API 检索 access_token。

这是我的网址:

https://disqus.com/api/oauth/2.0/access_token/?client_id=cvwNO7HaRwgYDq9anat8j7uzowJ8HBEz8gH7mUnmMhC0BKZZTkObc5d7o242liNG&grant_type=authorization_code&client_secret=Hrrgy1ZLcLN0qjmZhzXR2owET8cGazcbcGNxTlsWEJYiNfc3JcQLbKx2PYW6yNU7&redirect_uri=http://www.aftenposten.no&code=PM6QYwUJ

我收到一个错误:缺少必需的参数:grant_type

我正在使用以下代码来获取响应:

HttpWebRequest request = HttpWebRequest.CreateHttp(uri);
request.Method = "POST";
request.BeginGetResponse(new AsyncCallback(getAccessTokenResponse), request);

最佳答案

您需要在请求正文中传递表单数据,而不是作为 url 参数。试一试:

var uri = "https://disqus.com/api/oauth/2.0/access_token/"
HttpWebRequest request = HttpWebRequest.CreateHttp(uri);
var data = "client_id=[your client id]"
data += "&grant_type=authorization_code"
data += "&client_secret=[your client secret]"
data += "&redirect_uri=http://www.aftenposten.no&code=PM6QYwUJ"
var postData = Encoding.ASCII.GetBytes(data);

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;

using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}

var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

关于c# - disqus API 缺少必需的参数 : grant_type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11206184/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com