に私はより良いGoogleのサインインAPIを使用する方法を理解するために、このGoogleの認証チュートリアルをやっていると私は最近、このエラーを受け取った:致命的なエラー:)(メンバ関数のgetAttributesに呼び出し、アレイ
Fatal error: Call to a member function getAttributes() on array.
それは、 getPayload()
機能に
$this->client->verifyIdToken()->getAttributes();
:私がしようとしていたときに発生します。なぜこれが起こっているのか分かりません。私の設定はWindows 10で、WAMPサーバーを使ってこのアプリケーションを実行しています。どんな助けもありがとう。
<?php class GoogleAuth {
private $db;
private $client;
public function __construct(Google_Client $googleClient)
{
$this->client = $googleClient;
$this->client->setClientId('234sfsdfasdfasdf3223jgfhjghsdsdfge3.apps.googleusercontent.com');
$this->client->setClientSecret('fD5g4-B6e5dCDGASefsd-');
$this->client->setRedirectUri('http://localhost:9080/GoogleSigninTutorial/index.php');
$this->client->setScopes('email');
}
public function checkToken()
{
if(isset($_SESSION['access_token']) && !empty($_SESSION['access_token']))
{
$this->client->setAccessToken($_SESSION['access_token']);
}
else
{
return $this->client->createAuthUrl();
}
return '';
}
public function login()
{
if(isset($_GET['code']))
{
$this->client->authenticate($_GET['code']);
$_SESSION['access_token'] = $this->client->getAccessToken();
return true;
}
return false;
}
public function logout()
{
unset($_SESSION['access_token']);
}
public function getPayload()
{
return $this->client->verifyIdToken()->getAttributes();
}
}
?>
ありがとうございます!時間を節約しました!スコープを設定するときに、あなたが望むものを指定するときはちょうど1つです。ここを確認してください... http://stackoverflow.com/questions/14007560/get-userinfo-from-google-oauth-2-0-php-api – Albeis
良い点Albeis!また、ここですべてのスコープを見つけることができますhttps://developers.google.com/identity/protocols/googlescopesあなたが必要でない場合は、必要な範囲内の特定のキーワードを探すためにCtrl + F(Cmd + F)を使用しますそれが何と呼ばれているかを確かめてください。 – user