我正在尝试更新令牌,但我收到错误“远程服务器返回错误:(400)错误请求。” 我的代码是:
public static object Refresh_token(string client_id, string redirect_uri, string client_secret, string refresh_token, string scope)
{
var requestUrl = new StringBuilder("https://login.live.com/oauth20_token.srf");
requestUrl.Append("?grant_type=refresh_token");
requestUrl.AppendFormat("&client_id={0}", client_id);
requestUrl.AppendFormat("&redirect_uri={0}", HttpUtility.UrlEncode(redirect_uri));
requestUrl.AppendFormat("&client_secret={0}", HttpUtility.UrlEncode(client_secret));
requestUrl.AppendFormat("&refresh_token={0}", refresh_token);
WebRequest request = HttpWebRequest.Create(requestUrl.ToString());
request.Method = "GET";
request.ContentType = "application/x-www.form-urlencoded;charset=UTF-8";
WebResponse response = request.GetResponse();
using (var reader = new StreamReader(response.GetResponseStream()))
{
var json = reader.ReadToEnd();
return JsonConvert.DeserializeObject<Offline_access>(json);
}
}
如果我从浏览器发送,我会
{"error":"invalid_scope","error_description":"The provided request must include a 'scope' input parameter."}
我尝试用POST来做,但这是同样的问题。 有一些想法吗?
答案 0 :(得分:1)
似乎在Web服务器端更改了规范,并且它希望您发送范围参数。我不知道scope参数是什么以及你需要提供什么,但实际上你需要为requestUrl添加一行来添加它。
requestUrl.AppendFormat("&scope={0}", {whatever value the scope is suppose to be});