我需要從Google+獲取電子郵件,ID,名字和姓氏,才能爲用戶創建一個帳戶。爲了做到這一點,是我見過的所有例子都表示要做到這一點:Google+登錄:如何在一次異步呼叫中獲取電子郵件和其他個人資料信息?
// Get the email
gapi.client.load('oauth2', 'v2', function()
{
gapi.client.oauth2.userinfo.get().execute(function(resp) {
console.log(resp.email);
})
});
// Get the id, first name, and last name
gapi.client.load('plus', 'v1', function()
{
gapi.client.plus.people.get({'userId' : 'me'}).execute(function(resp) {
console.log(resp.id);
console.log(resp.name.givenName);
console.log(resp.name.familyName);
})
});
然而,有這個問題,因爲我希望能夠存儲resp.email,RESP。 id,resp.name.givenName,resp.name.familyName中的變量,以便在這兩個調用後,我可以使用該信息來創建一個用戶帳戶。由於execute()是一個異步調用,我無法做到這一點(至少在我的知識)。我認爲最簡單的解決方案是查看是否有一種方法可以一次性獲得我想要的所有內容(電子郵件,身份證,姓氏,名字),以便我可以在execute()函數內部創建用戶。我可以這樣做嗎?