Access to Gmail Atom feed with OAuth2 from Android app stopped working

偶尔善良 提交于 2019-12-22 18:34:33

问题


I have an Android app, which could access the Gmail Atom inbox feed for read-only access to unread emails (that's all I need). And, it recently stopped working.

It is using OAuth2 and GoogleAuthUtil. This how it works, with use of AsyncTask in a Service:

First, get a token:

String scope = "oauth2:https://mail.google.com/mail/feed/atom/";
token = GoogleAuthUtil.getToken(context, accountName ,scope );

Then use it to read the feed:

HttpURLConnection connection = (HttpURLConnection) new URL(urlString).openConnection();                 
connection.addRequestProperty("Authorization", "Bearer " + token);                                      
connection.connect();
//get the insputStream, read it, etc.

Problem is that this was working for approx. 1 month (May/June 2014). The app is even published on GooglePlay and has users. It was working and tested on different devices, different accounts, etc. I'm not 100% sure that it stopped working on all installations, but I can not get it back to work for myself and my devices. The app accessed the feed approx. every 10-20 minutes (based on user setting).

Do you have any idea why this could happend?

Since few days, I can still obtain the token, but response is only Unauthorized (401) response:

<HTML>
<HEAD><TITLE>Unauthorized</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1><H2>Error 401</H2>
</BODY>
</HTML>
  • I tried:
    • to invalidate the token every time
    • to fiddle with the scope
    • to rewoke access in my accounts settings
    • to reinstall
    • to update the Google-Play-Services library

etc., with no result.

After some research, I know about a client-id which needs to be generated to access various google APIs. I was able to generated such ID.

I tried to use that ID - to include it in the scope and run the app from a signed APK. But I cannot find any API in the list (https://console.developers.google.com) which could say GMAIL or ATOM FEED, or anything related to gmail. So I am unable to use it.

Any help appreciated.

EDIT - SOLVED Google resolved the issue, updated something :-) - now it works again.

来源:https://stackoverflow.com/questions/24366704/access-to-gmail-atom-feed-with-oauth2-from-android-app-stopped-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!