Gmail api范围和格式不匹配
我正在尝试为android编写一个小小的gmail客户端作为培训。 我从https://developers.google.com/gmail/api/quickstart/android中获取了gmail api指南示例,对其进行了一些修改以获取带有标题和正文的消息。 我将范围设置为GmailScopes.Gmail_modify
并编辑了主请求函数,如下所示:
private List getDataFromApi() throws IOException { // Get the labels in the user's account. String user = "me"; List labels = new ArrayList(); 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
这一天是我玩Google API Explorer的问题。 以下是我为解决这个问题所做的工作:
- 转到https://security.google.com/settings/security/permissions
- 选择您正在玩的应用程序,我的是Google API Explorer
- 单击删除>确定
- 下次,只需要确切地请求您需要的权限。
希望它有帮助:)
获得设备联系人的权限后,您必须批准选择的应对。 所以我第一次批准了元数据范围。 下次当我需要批准只读范围时,没有窗口可以做到。 因此,您需要从Google帐户中删除范围权限并重新安装应用。