如何使用 Google People API 获取登录用户的电子邮件地址?
我正在尝试检索登录用户的电子邮件地址,以便可以使用它与我的应用程序中的数据进行比较。我已经尝试了各种方法来获取它,但下面的代码只是返回undefined
.
function makeApiCall() {
gapi.client.people.people.get({
'resourceName': 'people/me',
'requestMask.includeField': 'person.names,person.emailAddresses'
}).then(function(resp) {
var name = resp.result.names[0].givenName;
var email = resp.result.emailAddresses[0].emailAddress;
authorizeButton.insertAdjacentHTML('beforebegin', '<small rel="' + email + '">Logged in as ' + name + '</small>');
});
}
将其更改var email = resp.result.emailAddresses[0];
为[object Object]
.
我也尝试过使用JSON.parse()
,但出现以下错误:
Uncaught SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at (index):285
at h.r2 (cb=gapi.loaded_0:119)
at xs (cb=gapi.loaded_0:122)
at Wq (cb=gapi.loaded_0:122)
at _.C.uea (cb=gapi.loaded_0:121)
at Ap (cb=gapi.loaded_0:115)
at <anonymous>
我还尝试了有关 Google People API 的其他未回答问题中的方法。