2016-07-26 6 views
1

id_token에서 가상 에이전트 나는 다음과 같은 세부 정보와 JSON 개체가 :Gmail에서 OAuth를

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

'googleapis'NodeJs 라이브러리를 사용하여 나는 위의 응답에 대한 이메일 주소를 얻을 수있는 방법. 나는 URL 사용하지 않으 : https://www.googleapis.com/oauth2/v1/userinfo?access_token=your_access_token

+0

: 왜 원하지 않는를 일반 URL에 대한 요청을 사용 하시겠습니까? :) 나는 개인적으로 그것이 더 쉽다고 생각한다. – Tholle

답변

1

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) 
    } 
    }); 
}