【发布时间】:2017-03-26 18:05:13
【问题描述】:
我正在尝试为 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
【问题讨论】:
标签: java android oauth-2.0 gmail-api