@Override
protected List< String > doInBackground( Void... params )
{
try
{
//This line below is the cause of the insufficient permissions error
ListMessagesResponse messagesWithLabels = mService.users().messages().list("me").setQ("label:inbox").execute();
/*for( Message m : messagesWithLabels.getMessages( ) )
{
if( m.size( ) > MAXSIZE )
{
List<MessagePartHeader> headers = m.getPayload( ).getHeaders( );
for ( MessagePartHeader header : headers )
{
if ( header.getName( ).equals("From") || header.getName().equals("Date")
|| header.getName().equals("Subject") || header.getName().equals("To")
|| header.getName().equals("CC")) {
messageDetails.put( header.getName( ).toLowerCase( ), header.getValue( ) );
}
}
messageDetails.put("snippet", m.getSnippet());
messageDetails.put("threadId", m.getThreadId());
messageDetails.put("id", m.getId());
messageDetails.put("body",m.getPayload().getBody().getData());
GmailFunctions.deleteThread( mService, "me", m.getId( ) );
messageDetails.clear( );
}
}*/
return getDataFromApi( );
}
catch ( Exception e )
{
mLastError = e;
cancel( true );
return null;
}
}
I have marked the line which is causing a 402 Insufficient permissions domain: global error. If I comment out said line the program will return the labels and print them to the screen without the permissions error. I have signed my release apk and set up the Google Play Developer console. The app is signing just fine it's SHA1 and I followed the sample application which retrieves credentials.
https://developers.google.com/gmail/api/quickstart/java
What to do about insufficient permissions?
Thank you.
The creation of mservice:
private class MakeRequestTask extends AsyncTask< Void, Void, List< String > > {
private com.google.api.services.gmail.Gmail mService = null;
private Exception mLastError = null;
ArrayList<String> sRemovalIds = new ArrayList<String>( );
List< String > inserts = new ArrayList< String >( );
Map<String, Object> messageDetails = new HashMap<String, Object>( );
public MakeRequestTask( GoogleAccountCredential credential )
{
HttpTransport transport = AndroidHttp.newCompatibleTransport( );
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance( );
mService = new com.google.api.services.gmail.Gmail.Builder(
transport, jsonFactory, credential )
.setApplicationName( "Gmail API Android Quickstart" )
.build( );
}
@Override
protected List< String > doInBackground( Void... params )
{
try
{
ListMessagesResponse messagesWithLabels = mService.users().messages().list("me").setQ("label:inbox").execute();
/*for( Message m : messagesWithLabels.getMessages( ) )
{
if( m.size( ) > MAXSIZE )
mService
? It is probably there your permission issue is. – Bandlerhttp-requests
over at the Oauth Playground, and try to figure out what Gmail API permission scope you need. – Bandler