Contacts API and OAuth2

1,409 views
Skip to first unread message

Rebecca Miller-Webster

unread,
Jan 13, 2012, 4:21:48 PM1/13/12
to google-co...@googlegroups.com
Hi,

I'm successfully authenticating via OAuth2 and am able to see user info via: 

However, if I try:
I get a 401 Token Invalid - AuthSub token has wrong scope

When I am redirected to authenticated, it says the app wil "Manage contacts," so I am pretty sure the scope is correct.  However, I'm obviously not using AuthSub.

Is OAuth2 not available at all for the Contacts API?

Thanks,
Rebecca

Alain Vongsouvanh

unread,
Jan 19, 2012, 11:59:42 AM1/19/12
to google-co...@googlegroups.com
Hello Rebecca,

Sorry about the delay in getting back to you! I can assure you that Contacts API does support OAuth 2.0 but you might have to specify the token in the request header:

Authorization: Bearer <OAUTH_2_0_ACCESS_TOKEN>

You can try this behavior on OAuth Playground.

Best,
Alain

--
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
google-co...@googlegroups.com
To unsubscribe from this group, send email to
google-contacts...@googlegroups.com
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html



--
Alain Vongsouvanh | Developer Programs Engineer

Rebecca Miller-Webster

unread,
Jan 23, 2012, 6:25:43 PM1/23/12
to google-co...@googlegroups.com
Hi Alain,
Thanks for getting back to me.  

When I try it out in the OAuth2 playgroud with Step 3 hitting 'https://google.com/m8/feeds/contacts/default/full', I get:
Something bad happened: 500 HTTP error. Message: {"success": false, "error": "An error occured while processing the request, please retry"}

I did change the header in my code to Authorization: Bearer XXXX but I am still getting a 401 error with the message: "Token invalid - AuthSub token has wrong scope"
I do see a 302 redirect on https://accounts.google.com/o/oauth2/approval which I wasn't seeing before.  

Any ideas?

Thanks,
Rebecca

Tony

unread,
Feb 2, 2012, 10:38:36 PM2/2/12
to google-co...@googlegroups.com
The below codes work for me, see if you are doing something different

    private static final String SCOPE = "https://www.google.com/m8/feeds";

    GenericUrl shortenEndpoint = new GenericUrl("https://www.google.com/m8/feeds/contacts/default/full/");
    HttpRequest request = rf.buildGetRequest(shortenEndpoint);
    GoogleHeaders headers = new GoogleHeaders();
    headers.setContentType("application/x-www-form-urlencoded");
    headers.setAuthorization("OAuth " + accessToken);
    request.setHeaders(headers);   
    request.getHeaders().set("GData-Version", "3.0");
    HttpResponse shortUrl = request.execute();
Reply all
Reply to author
Forward
0 new messages