2017-05-19 3 views
0

oAuth2で認証した後にメールアドレスを取得しようとしています。私はGoogleのアカウントを使用して検証するとき、私はcodeを取得した後、私はこのように、行くとGoogleプラスからユーザーを取得:oAuth2で認証した後、電子メールアドレスを取得するにはどうすればよいですか? - google-api-nodejs-client

let oAuth2Client = new auth.OAuth2(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_CLIENT_CALLBACK); 
const tokens = await getToken(oAuth2Client, code); 
oAuth2Client.setCredentials(tokens); 
plus('v1').people.get({ userId: 'me', auth: oAuth2Client }, function(err, response) { 
    .... This repsonse is the full user object from Google Plus 
}); 

がどのように私は、電子メールアドレス、または電子メールアドレスのリストを得るのですか?私は他のすべてのGoogle Plusの情報を望んでいません。私はすでに範囲をemailに設定しましたが、私はまだ多くの他の情報を得ています。私はplus以外のものに依頼する必要があると仮定していますが、文書で何をすべきか分かりません。

答えて

0

あなたは電子メールのスコープ(https://www.googleapis.com/auth/userinfo.email)を設定している場合は、oauth2("v2").userinfo.v2.me.getを使用することができます。

var google = require('googleapis'); 

.... 

google.oauth2("v2").userinfo.v2.me.get({ 
    auth: oAuth2Client 
}, function(e, profile) { 
    if ("email" in profile) { 
     console.log(profile.email); 
    } else { 
     console.log("scope email not set"); 
    } 
}); 
関連する問題