Thank you both, I figured it out.
Nikolay was correct in scrutinizing the use of "mail" aus AUTH_TOKEN_TYPE.
There is some (old?) documentation that lists this as an alias for Gmail.
This alias even returns a token, which in turn does not work when used to
authenticate with the atom feed.
So I switched the AUTH_TOKEN_TYPE to
"oauth2:https://mail.google.com/mail/feed/atom/". The token from that scope
worked, right out of the box.
The HTTP GET works like this now:
HttpClient client = new DefaultHttpClient();
HttpGet method = new
HttpGet("https://mail.google.com/mail/feed/atom/unread");
method.setHeader("Bearer " + token);
HttpResponse response;
try {
response = client.execute(method);
} catch (Exception e) { }
// Now parse response as normal.
On Sunday, July 29, 2012 11:21:46 PM UTC-7, Nikolay Elenkov wrote:
>
> On Mon, Jul 30, 2012 at 2:32 PM, JP <> wrote:
> > I am trying to authenticate with the Gmail atom feed using the
> > authentication token of the Gmail account, obtained from AccountManager.
> >
> > I have no problem pulling the authentication token for a Google Account
> > registered on the device, using AccountManagergetAuthToken() with the
> > authTokenType "mail", but the authentication token does not register
> with
> > the atom feed. I've played with a few variations, but all I get is a 401
> /
> > Unauthorized response from Google.
> > Basically, I've tried to GET
> https://mail.google.com/mail/feed/atom/unread
> > adding in a "Authorization" header item with "Bearer <authentication
> > token>", but that didn't work.
>
> Unless there is an official API, this may or may not work.
>
> What you are getting from AccountManager is a ClientLogin token, but
> you are trying to use is as if it were an OAuth token, that's probably
> why you get an error. For ClientLogin you need something like:
>
> Authorization: GoogleLogin auth=token
>
> Again, this may or may not work, especially since ClientLogin is
> deprecated.
> I am also not sure whether the 'mail' token will work for the RSS feed.
>
> To get an OAuth token, you need to use 'oauth2:scope' where scope
> is the scope for the particular service, you need to find out what it is
> for this feed.
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en