Search code examples
c#oauthwindows-8google-readergoogle-oauth

Get google reader subscription list using OAuth 2 authentication in C#


I have been accessing google reader in C# code for quite some time using ClientLogin authentication. I have been working on a Google Reader client for Windows 8 and decided to use OAuth 2 authentication which is more secure. I can login, get access token and refresh token, But I have failed to use the access token to make any api calls getting a 401 Unauthorized error. And my token comes with many characters starting with "ya29.". I hope the token is right. I am using the HttpClient class while passing the "Authorization:" header to it. Could someone please help me out? Below is my code snippet

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;
    }

Solution

  • I recommend using RestSharp. It's a lot easier to use than HttpClient and in addition has support for OAuth 1 & 2. Here's a tutorial on how to use it:

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