I am trying to access the Gmail API using an Android application.
I have successfully requested and received an access token using all available scope combinations.
But it seems that every time I actually try to use the Gmail API command I am getting a 403 exception reading: Access not configured please use Google developers console to activate the api...
Needless to say the API is activated and a client key was created using the correct package name & sha1 code. Same client ID works well with Google Plus features.
Anyone having this issue or succeeded in connecting to the Gmail api from Android?
Thanks
Here's the log:
09-04 21:40:54.014: W/System.err(26717): com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
09-04 21:40:54.014: W/System.err(26717): {
09-04 21:40:54.014: W/System.err(26717): "code" : 403,
09-04 21:40:54.014: W/System.err(26717): "errors" : [ {
09-04 21:40:54.014: W/System.err(26717): "domain" : "usageLimits",
09-04 21:40:54.014: W/System.err(26717): "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project.",
09-04 21:40:54.014: W/System.err(26717): "reason" : "accessNotConfigured"
09-04 21:40:54.014: W/System.err(26717): } ],
09-04 21:40:54.014: W/System.err(26717): "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project."
09-04 21:40:54.014: W/System.err(26717): }
Are there any other API's that need to be enabled in the API Console except Google+ API and Gmail API?
EDIT:
I have found out that using a WebView based authentication will result in an access token that will grant Gmail API access but this is not a valid solution because the token is short lived. As for now the GoogleAuthUtil will grant a token but it's privileges are not sufficient for using the Gmail API. anyone had success in connecting Android with the Gmail API and would like to share?
EDIT2:
Here are snippets of what I am doing:
Getting the token:
token = GoogleAuthUtil.getToken(MainActivity.this, Plus.AccountApi.getAccountName(mGoogleApiClient), scope);
Trying to fetch messages from the Gmail API:
GoogleCredential credential = new GoogleCredential().setAccessToken(token);
JsonFactory jsonFactory = new JacksonFactory();
HttpTransport httpTransport = new NetHttpTransport();
service = new Gmail.Builder(httpTransport, jsonFactory, credential).setApplicationName("GmailApiTP").build();
ListMessagesResponse messagesRespose;
List<Message> m = null;
ArrayList<String> ids = new ArrayList<String>();
ids.add("INBOX");
try {
messagesRespose = service.users().messages().list("me").setLabelIds(ids).setQ("From: something")
.execute();
m = messagesRespose.getMessages();
} catch (IOException e) {
e.printStackTrace();
}
The exception is caught when use the Gmail API service. In addition I have tried clearing the token and asking for a new one with the same result.