2016-07-26 46 views
1

获得电邮我有以下细节的JSON对象:从id_token的Gmail的OAuth

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

使用图书馆的NodeJS“googleapis”我怎样才能获得的电子邮件地址上面的响应。我不希望使用的网址:https://www.googleapis.com/oauth2/v1/userinfo?access_token=your_access_token

+0

只是出于好奇:你为什么不想要使用请求到正规的URL? :)我个人认为这很容易。 – Tholle

回答

1

获得一个auth-对象像introduction,然后你可以使用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) 
    } 
    }); 
}