为什么谷歌服务器在尝试获取令牌时会返回错误401?

时间:2011-12-22 12:43:07

标签: c# token google-reader http-status-code-401

我正在尝试为谷歌阅读器开发api,当我试图获取令牌时,会产生以下错误:

System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()

首先我要开会......这完美无缺。然后调用以下方法获取令牌:

public String setToken()
{
    HttpWebResponse response;
    HttpWebRequest request;
    cookie = new Cookie("SID", this.sessionID, "/", ".google.com");
    String url = "http://www.google.com/reader/api/0/token";

    request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "GET";
    request.CookieContainer = new CookieContainer();
    request.CookieContainer.Add(this.cookie);

    response= (HttpWebResponse)request.GetResponse();
    using (var stream = response.GetResponseStream())
    {
        StreamReader r = new StreamReader(stream);
        this.token = r.ReadToEnd();
    }
    return this.token;
}

此行中正在生成异常:

response= (HttpWebResponse)request.GetResponse();

有人知道可能导致此错误的原因吗?

PS。我读到了这个问题:Why am I getting a 401 (Unauthorized) error when POSTing to Google Reader API?但是当他试图发帖时他得到了这个错误。

1 个答案:

答案 0 :(得分:2)

根据Eric Mann的说法,谷歌发生了变化:

“事实证明,Google已更改了Reader API的身份验证部分。现在,您不必在发出请求时在Cookie中传递SID,而是使用最初传递的”Auth“键设置身份验证标头SID。“

Source