0

我正在尝试更新令牌,但出现错误“远程服务器返回错误:(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 来做,但这是同样的问题。有什么想法吗?

4

1 回答 1

1

似乎 web 服务器端的规范发生了变化,它希望您发送一个范围参数。我不知道范围参数是什么以及您需要为其提供什么,但基本上您需要为 requestUrl 添加一行来添加它。

requestUrl.AppendFormat("&scope={0}", {whatever value the scope is suppose to be}); 
于 2013-05-22T14:43:00.453 回答