3
votes

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?

2
Can you try specifying one scope only - "mail.google.com" ?noogui
Still 403, but when I run my code in a new project, everything works.Sartakov Dmitrij
According to this gmail forum, clearing your cache usually resolves this issue. Must be the reason your new projects works.noogui

2 Answers

0
votes

you should remove the "metadata" scope.

check app permissions to make sure you have only these 3 scopes:

  1. https://mail.google.com/
  2. gmail.modify
  3. readonly

, or else remove the permissions and add them again.

0
votes

This is another disappointing design in the Gmail API. I resolved this issue with the following steps:

  1. Remove GmailScopes.GMAIL_METADATA from scopes.
  2. Remove the 'StoredCredential' file from your local FileSystem. This file is generated by Google's GoogleAuthorizationCodeFlow instance when the setDataStoreFactory gets call to store your credential.
  3. Re authorize your app by signing in again https://accounts.google.com/o/oauth2/auth?access_type=offline....

Hope this helps you guys out.