gpt4 book ai didi

java - Gmail api 范围和格式不匹配

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:26:49 26 4
gpt4 key购买 nike

我正在尝试为 android 编写微型 gmail 客户端作为培训。我从 https://developers.google.com/gmail/api/quickstart/android 中获取了 gmail api 指南示例稍微修改它以通过线程获取带有标题和正文的消息。我将范围设置为 GmailScopes.Gmail_modify 并将主要请求函数编辑为:

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

最佳答案

这正是我最近在使用 Google APIs Explorer 时遇到的问题。这是我为解决它所做的工作:

  1. 转到 https://security.google.com/settings/security/permissions
  2. 选择您正在玩的应用,我的是 Google APIs Explorer
  3. 点击删除 > 确定
  4. 下次,只需准确请求您需要的权限即可。

希望对你有帮助:)

关于java - Gmail api 范围和格式不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40566099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com