2016-11-11 79 views
1

我在Ruby中製作一個簡單的應用程序我需要獲取用戶的電子郵件。我正在使用適用於Ruby的Google API客戶端。我無法獲取用戶的電子郵件地址,我一直在研究這個主題2天,並且無法在用戶登錄後獲得用戶的電子郵件。我不想用Google+登錄按鈕來完成此操作我希望以編程方式進行操作。我得到谷歌授權,但不知道如何檢索登錄用戶的用戶信息。我試過也嘗試過client = Google::APIClient.new,但我沒能力。以下是我的代碼。我會感謝你的幫助。無法從Ruby中的google api獲取用戶信息

scopes = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly', 'https://www.googleapis.com/auth/plus.login','https://www.googleapis.com/auth/userinfo.email'] 
    client_secrets = Google::APIClient::ClientSecrets.load(SECRETS_PATH) 
    auth_client = client_secrets.to_authorization 
    auth_client.update!(
     :additional_parameters => {"access_type" => "offline"} 
) 
    auth_client.update!(
     :scope => scopes, 
     :redirect_uri => 'http://localhost:3000/google_oauth2') 

回答

1

嘿在此您可以參閱寶石Google Plus

我已經實現相同的,它的正常工作從這些方面。

步驟,將繼偕

  1. 首先通過包括它的Gemfile安裝GOOGLE_PLUS寶石。

  2. 產生來自谷歌加的谷歌控制檯+

    https://console.developers.google.com

  3. 包括它喜歡它

    GooglePlus.api_key = 'your key' 
    
  4. 使用前,API密鑰按ID搜索谷歌

    任何人
    person = GooglePlus::Person.get(123) 
    

您將獲得特定用戶

+0

嘿,感謝完整的用戶信息很多,讓我來試試吧。 –

+1

如果您在此處只需要幫助,請點擊此處 –

+0

Google+現已老化,不應使用。有沒有其他方法? – archana