使用C#中的OAuth 2身份验证获取Google阅读器订阅列表

时间:2013-01-10 08:23:11

标签: c# oauth windows-8 google-reader google-oauth

我使用ClientLogin身份验证已经使用C#代码访问谷歌阅读器很长一段时间了。我一直在为Windows 8开发Google Reader客户端,并决定使用更安全的OAuth 2身份验证。我可以登录,获取访问令牌和刷新令牌,但我没有使用访问令牌使任何api调用获得401 Unauthorized错误。我的令牌带有许多以“ya29”开头的字符。我希望令牌是对的。我正在使用HttpClient类,同时将“Authorization:”标头传递给它。有人可以帮帮我吗?以下是我的代码段

private async Task<string> HttpGet()
    {
    string url = "http://www.google.com/reader/api/0/subscription/list";
        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", 
            String.Format("OAuth access_token={0}", Token);

        var response = await client.GetAsync(url);
        var content = await response.Content.ReadAsStringAsync();
        return content;
    }

3 个答案:

答案 0 :(得分:1)

您似乎没有使用正确的授权标头格式。根据{{​​3}},标题应为:

Authorization: Bearer ya29.xxxxxxxxxxxx

答案 1 :(得分:0)

我建议使用RestSharp。它比HttpClient更容易使用,另外还支持OAuth 1&amp; 2.这是一个如何使用它的教程:

http://www.codeproject.com/Articles/321291/Google-OAuth2-on-Windows-Phone

答案 2 :(得分:0)

我可以提出建议吗?

我讨厌编写oauth代码。

向您的应用程序添加Google身份验证的最简单方法是使用Windows Azure移动服务(WAMS)。 WAMS将通过他们的SDK处理oauth详细信息,该SDK还支持Live ID,FaceBook和Twitter。它是C#和JavaScript,Android和iOS。最重要的是,它是免费的。

引用:http://www.windowsazure.com/en-us/home/features/mobile-services/

相关问题