Question

I need to obtain OAuth2 authentication token to pass it to the server so it can fetch list of Google Reader feeds for the user. Server is .NET - I have no access to it or to it's code but most likely it is using unofficial Reader API

I was able to use Android Account manager to obtain valid token for this purpose with the following code (notice that authTokenType="reader")

Account account = accounts[0];
manager.getAuthToken(account, "reader", null, this, new AccountManagerCallback<Bundle>() {
    public void run(AccountManagerFuture<Bundle> future) {
        try {
            // If the user has authorized your application to use the tasks API
            // a token is available.
            String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
            // Now you can send the token to API...
            cacheManager.putString(GOOGLE_AUTH, token);
            GoogleReaderManager.startAddFeedActivity(AddGoogleReaderSourcesActivity.this);
            finish();
        } catch (OperationCanceledException e) {
            Log.e(TAG, "User cancelled", e);
            finish();
        } catch (Exception e) {
            Log.e(TAG, "Failed to obtain Google reader API_KEY", e);
        }
    }
}, null);

The code above works fine when I send token to the server side .Net app: the app is able to retrieve the list of Reader feeds.

The problem is that this only works for "Google inside" devices. On Nook I have no such luck since there's no way that I was able to find to add Google account to the account manager. So I'm trying to it using OAuth 2 protocol as described here

It works fine as far as obtaining the token: User approves the app from the mobile page which returns the code token which then mobile app exchanges for the Auth token. However this token will not work with the server process. I have a feeling that perhaps I'm using the wrong scope in this URL:

https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.google.com/reader/api/0/subscription/list&redirect_uri=http://localhost&approval_prompt=force&state=/ok&client_id={apps.client.id}

Scopes that I did try in various combinations:

  1. https://www.google.com/reader/api
  2. https://www.google.com/reader/api/0
  3. https://www.google.com/reader/api/0/subscription/list
  4. https://www.google.com/reader/api+https://www.google.com/reader/atom

Here's example of JSON that is returned from get token POST

{"expires_in":3600,
     "token_type":"Bearer",
     "access_token":"ya29.AHES6ZSEvuUb6Bvd2DNoMnnN_UnfxirZmf_RQjn7LptFLfI",
     "refresh_token":"1\/bUwa5MyOtP6VyWqaIEKgfPh08LNdawJ5Qxz6-qZrHg0"}

Am I messing up scope or token type? Not sure how to change a token type. Any other ideas?

P.S. Google account login page asks: Manage your data in Google Reader, that's why I suspect that the scope is wrong

Was it helpful?

Solution

I got it working for https://www.google.com/reader/api/0/subscription/list. So thought of sharing with you.

I have valid access_token:

This is what i tried to resolve it (partially) :

  • Google provides OAuth 2.o playgound; where they actually simulate all aspects of OAuth 2.0 as well as final API call to fetch data. I found this very helpful as it clearly shows what is being sent to request. Here is the URL : https://developers.google.com/oauthplayground/
  • Using this, i tweaked my api call below and it works :)

    public static  String getReaderContent(String accessToken){
       String url = "https://www.google.com/reader/api/0/subscription/list" ; 
    
       HttpClient client = new HttpClient();
    
       GetMethod method = new GetMethod(url);
       String response="";
       method.setRequestHeader("Authorization", "OAuth "+accessToken);
       try {
         int statusCode = client.executeMethod(method);
         String response= method.getResponseBodyAsString();
    
         System.out.println("response " + responseStr);
       } catch (HttpException e) {
         e.printStackTrace();
       } catch (IOException e) {
        e.printStackTrace();
      }
    return response;
    }
    

So this works properly fine for getting subscription list; but have not been able to make it work for reader api which you have mentioned in your question.

Let me know if you have got way around google reader API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top