Google OAuth API to get user's email address?

前端 未结 11 829
栀梦
栀梦 2020-11-29 01:38

I am playing with Google\'s OAuth 2.0 Playground using my own personal Google account, but I cannot seem to recover my Gmail address using the playground.

The scope

11条回答
  •  萌比男神i
    2020-11-29 01:53

    https://developers.google.com/gmail/api/v1/reference/users/getProfile

    For gmails api, add this to nodejs code:

    function getUsersEmail (auth) {
      const gmail = google.gmail({version: 'v1', auth})
      gmail.users.getProfile({
        userId: 'me'
      }, (err, {data}) => {
        if (err) return console.log('The API returned an error: ' + err)
        console.log(data.emailAddress)
      })
    }
    

    Gmails api: https://developers.google.com/gmail/api/guides/

提交回复
热议问题