Gmail api scope & format mismatch

梦想的初衷 提交于 2019-12-18 06:49:38

问题


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


回答1:


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 :)




回答2:


you should remove the "metadata" scope.

check app permissions to make sure you have only these 3 scopes:

  1. https://mail.google.com/
  2. gmail.modify
  3. readonly , or else remove the permissions and add them again.



回答3:


After getting permissions to device Contacts you have to approve chosen copes. So first time I approved metadata scope. Next times when I needed to approve readonly scope, there was no window to do it. So you need to delete scopes permissions from google account and reinstall app.



来源:https://stackoverflow.com/questions/40566099/gmail-api-scope-format-mismatch

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