Gmail API范围和格式不匹配 [英] Gmail api scope & format mismatch

查看:70
本文介绍了Gmail API范围和格式不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Android编写微型gmail客户端作为培训. 我从 https://developers.google.com/gmail/api中获取了gmail API指南示例/quickstart/android 对其进行了一些修改,以获取带有标头&的消息身体通过线程.我将范围设置为GmailScopes.Gmail_modify并按以下方式编辑了主要请求功能:

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;
        }

但是我总是得到

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"
                                                                           }

我尝试了不同的范围配置,但似乎服务范围始终设置为GmailScopes.GMAIL_METADATA

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

推荐答案

这些天正是我在使用Google APIs Explorer时遇到的问题.这是我为解决该问题所做的事情:

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

  1. 转到 https://security.google.com/settings/security/permissions
  2. 选择正在使用的应用,我的就是Google APIs Explorer
  3. 点击删除>确定
  4. 下次,只需准确要求您需要的权限即可.
  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.

希望对您有所帮助:)

这篇关于Gmail API范围和格式不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆