Gmail api 范围 &格式不匹配 [英] Gmail api scope & format mismatch
问题描述
我正在尝试为 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:
- 转到https://security.google.com/settings/security/permissions
- 选择您正在使用的应用,我的是 Google APIs Explorer
- 点击删除">确定"
- 下次,只需准确请求您需要哪些权限.
希望有帮助:)
这篇关于Gmail api 范围 &格式不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!