2014-02-18 101 views
1

我有谷歌登錄工作在我的網站,使用codeigniter-oauth2只是在最後一步,所有我得到的是:Codeigniter上的Google Login API返回空userinfo。有任何想法嗎?

  • 的access_token

  • 到期

,沒有別的!

這裏就是我請求數據:

$url = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&' . http_build_query(array('access_token' => $token->access_token,));

它確實充分循環,但是當我檢查出:

file_get_contents($url)我什麼也沒得到!

這些都是我的範圍:

  • https://www.googleapis.com/auth/userinfo.profile
  • https://www.googleapis.com/auth/userinfo.email
  • https://www.googleapis.com/auth/plus.profile.emails.read

我缺少一個範圍?還是我錯誤地要求信息?

此外,我正在使用v1,應該使用v2來代替嗎?

+1

你可能會有更好的運氣與更近的東西。 https://github.com/google/google-api-php-client – DaImTo

回答

1

您的示波器看起來不正確。嘗試:

  • 「輪廓」

接下來,你應該確保你的訪問令牌是有效的。您可以使用the tokeninfo endpoint to check your access token,這會告訴您諸如令牌的發放方式等等。

最後,正如@daimto建議的那樣,您應該從the Google+ PHP example開始,這將爲您設置一個客戶端庫,這使得向Google進行API調用和使用Google OAuth 2實現變得更加容易。

+0

非常感謝。我調換了範圍並嘗試了測試,似乎已經檢查出來了。我猜這個錯誤發生在我使用訪問令牌通過調用'file_get_contents'來獲取用戶信息時:''https://www.googleapis.com/oauth2/v1/userinfo?alt=json&'.http_build_query(array( 'access_token'=> $ token-> access_token,)'?這是否正確?感謝您的幫助! – Prodikl

0

我最終做了什麼,因爲我的服務器不支持IPv6,所以使用了Google的Javascript API。我只是遵循谷歌的教程,它運行良好。

相關問題