从id_token Gmail OAuth获取电子邮件

我有一个JSON对象具有以下细节:

{ access_token: 'access_token', token_type: 'Bearer', expires_in: 3599, id_token: 'longstring' } 

使用NodeJs库'googleapis'我怎样才能得到上述响应的电子邮件地址。 我不想使用以下url: https : //www.googleapis.com/oauth2/v1/userinfo?access_token = your_access_token

像介绍中那样获取auth对象,然后可以使用getProfile方法:

 function getEmailAddress(auth, callback) { gmail.users.getProfile({ auth: auth, userId: 'me' }, function(err, response) { if (err) { console.log('The API returned an error: ' + err); callback(err, null); } else { callback(null, response.emailAddress) } }); }