Error 500 backendError with Gmail API and Google Node API Client

I am trying to use the new Gmail API with the Google Node API Client . I created a new project from the developer console, set the new client identifier "Service Account" and enabled access to the API.

As a proof of concept, I'm just trying to list the threads in my inbox. When I turn on the OAuth 2.0 switch for the API browser and enter my email address, the request is successful and I see a JSON response with the data.

Now I'm trying to do the same in Node:

var googleapis = require('googleapis'); var SERVICE_ACCOUNT_EMAIL = '...SNIP...'; // generated by: openssl pkcs12 -in ...SNIP...p12 -out key.pem -nocerts -nodes var SERVICE_ACCOUNT_KEY_FILE = 'key.pem'; var jwt = new googleapis.auth.JWT( SERVICE_ACCOUNT_EMAIL, SERVICE_ACCOUNT_KEY_FILE, null, ['https://www.googleapis.com/auth/gmail.readonly']); googleapis .discover('gmail', 'v1') .execute(function(err, client) { jwt.authorize(function(err, result) { if(err) console.error(err); else console.log(result); client.gmail.users.threads.list() .withAuthClient(jwt) .execute(function(err, result) { if(err) console.error(err); else console.log(result); }); }); }); 

First, I print the results of calling authorize() , which looks like it is returning a token, so I think I configured all the OAuth settings correctly:

 { access_token: '...SNIP...', token_type: 'Bearer', expires_in: 1404277946, refresh_token: 'jwt-placeholder' } 

Then I try to use the API, but I get an error:

 { errors: [ { domain: 'global', reason: 'backendError', message: 'Backend Error' } ], code: 500, message: 'Backend Error' } 

At this moment I do not know what else to try. I think OAuth is working fine because I don't have authentication errors. I also think the API itself is working, and my account is beautiful, because I can use it through the API API. I see no signs that the Node library is to blame either. In short, I have no idea what the problem is. Any ideas?

+6
source share
1 answer

You are using a service account to check your GMail requests. As far as I know, your service account will not have Gmail, only users have GMail. For this reason, you will need to make an OAuth2 stream with the user ( see here, for example, ).

0
source

Source: https://habr.com/ru/post/971636/


All Articles