Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
526 views
in Technique[技术] by (71.8m points)

java - Gmail api scope & format mismatch

I'm trying to write tiny gmail client for android as training. I took gmail api guide sample from https://developers.google.com/gmail/api/quickstart/android modified it a little to get messages with headers & body by threads. I set scopes to GmailScopes.Gmail_modify and edited main request function as this:

private List<String> getDataFromApi() throws IOException {
            // Get the labels in the user's account.
            String user = "me";
            List<String> labels = new ArrayList<String>();
            ListLabelsResponse listResponse =
                    mService.users().labels().list(user).execute();
            ListThreadsResponse listThreads = null;
            try {
             listThreads = mService.users().threads().list(user).execute();
            } catch (IOException ioex){
                Log.e(LOG_TAG, "First: " + ioex.toString());
            }

            for (Thread thread : listThreads.getThreads()) {
                try {
                    thread = mService.users().threads().get(user, thread.getId()).setFormat("full").execute();
                } catch (IOException ioex){
                    Log.e(LOG_TAG, "Second: " + ioex.toString());
                }
                for(Message message : thread.getMessages()){
                    labels.add(message.getId());
                }

            }
            return labels;
        }

But I always get

Second: GoogleJsonResponseException: 403 Forbidden            {
                                                                             "code" : 403,
                                                                             "errors" : [ {
                                                                               "domain" : "global",
                                                                               "message" : "Metadata scope doesn't allow format FULL",
                                                                               "reason" : "forbidden"
                                                                             } ],
                                                                             "message" : "Metadata scope doesn't allow format FULL"
                                                                           }

I tried different scopes configurations but seems like service scope is always set to GmailScopes.GMAIL_METADATA

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is exactly my problem these day when playing with Google APIs Explorer. And here is what I did to solve it:

  1. Go to https://security.google.com/settings/security/permissions
  2. Choose the app you are playing with, mine is Google APIs Explorer
  3. Click Remove > OK
  4. Next time, just request exactly which permissions you need.

Hope it help :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...