Gre*_*een 4 java android oauth-2.0 gmail-api
我正在尝试为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;
}
Run Code Online (Sandbox Code Playgroud)
但我总是得到
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"
}
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的范围配置,但似乎服务范围始终设置为 GmailScopes.GMAIL_METADATA
这是使用Google API Explorer玩这一天的问题.以下是我为解决这个问题所做的工作:
希望它有帮助:)