Does the Gmail API support JWT?

I want to access the Gmail API using NodeJS.

I use the server-to-server approach (see this ), but when I execute the code below, I get backEndError, code 500 from the Google API.

Any ideas?

var authClient = new google.auth.JWT( 'email', 'key.pem', // Contents of private_key.pem if you want to load the pem file yourself // (do not use the path parameter above if using this param) 'key', // Scopes can be specified either as an array or as a single, space-delimited string ['https://www.googleapis.com/auth/gmail.readonly'] ); authClient.authorize(function(err, tokens) { if (err) console.log(err); gmail.users.messages.list({ userId: 'me', auth: authClient }, function(err, resp) { // handle err and response if (err) { console.log(err); }); 
+5
source share
1 answer

Yes, I have the same problem. If I use the scope https://mail.google.com , I get

 403 { "error" : "access_denied", "error_description" : "Requested client not authorized." } 

And if I use the scope https://mail.google.com/ "(note the / at the end), I get

 403 'Forbidden' 

This seems to be due to the use of the JWT and the service account.

0
source

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


All Articles