I have error when implement Gmail API for Android. My Scopes:
private static final String[] SCOPES = { GmailScopes.GMAIL_LABELS, GmailScopes.GMAIL_COMPOSE,
GmailScopes.GMAIL_INSERT, GmailScopes.GMAIL_MODIFY, GmailScopes.GMAIL_READONLY, GmailScopes.MAIL_GOOGLE_COM };
I can to get messages Id:
Log.i("messages.get(0)", messages.get(0).toPrettyString());
In Android Monitor:
I/messages.get(0): {"id": "1588ae7e991a62f2","threadId" : "1588ae7e991a62f2"}
But when I try to get certain message:
getGmailMessage(mService, user, "1588ae7e991a62f2");
public static Message getGmailMessage(Gmail service, String userId, String messageId) throws IOException {
Message message = service.users().messages().get(userId, messageId).execute();
System.out.println("Message snippet: " + message.getSnippet());
System.out.println("Message getHeaders: " + message.getPayload().getHeaders().get(0));
System.out.println("Message toPrettyString: " + message.getPayload().toPrettyString());
return message;
}
I get an error:
The following error occurred: 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" }
When I run my code in a new project, everything works. Why?
you should remove the "metadata" scope.
check app permissions to make sure you have only these 3 scopes:
, or else remove the permissions and add them again.
This is another disappointing design in the Gmail API. I resolved this issue with the following steps:
Hope this helps you guys out.
尝试将GmailScopes.GMAIL_METADATA
添加到范围或只使用GmailScopes.all()
方法
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.