2013-11-10 26 views
1

我需要從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()函數內部創建用戶。我可以這樣做嗎?

回答

0

如你所說,你可以調用另一個函數從執行匿名函數來 做進一步的代碼...... 或者如果你喜歡獨立的代碼位,存儲在全局變量這幫變量並調用宇應用代碼功能,或者我可能會推薦使用window.setTimeout(your_fn,1); 異步調用你的函數給瀏覽器一些UI響應。 有許多不同的方法來編碼它。

另請注意,error "Access Not Configured.

相關問題