2014-06-28 70 views
1

我剛剛下載了最新的Google API PHP,我試着用「使用Google登錄」腳本進行測試。該API引發此異常顯然是未捕獲:Google API PHP:createAuthURL()上的未捕獲異常?

Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'No scopes specified' in /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php:178 Stack trace: #0 /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php(237): Google_Client->prepareScopes() #1 /home/rlcoachi/public_html/hidden/googlelogin/api.php(76): Google_Client->createAuthUrl() #2 {main} thrown in /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php on line 178

線74-77我api.php腳本是:

else 
{ 
    //For Guest user, get google login url 
    $authUrl = $gClient->createAuthUrl(); 
} 

gClient是這一直是安裝有ID,祕密,URL一個Google_Client對象,關鍵

Full script is available here

回答

1

轉到文件命名的GoogleLogin/src目錄/谷歌/ Client.php

搜索

protected $scopes = array(); 

然後填寫與範圍的陣列狀

protected $scopes = array("userinfo.email", "userinfo.profile"); 

,如果你想獲得用戶的EMAILID以及配置文件的詳細信息...

1

嘗試:

$client->setScopes(array(
    'https://www.googleapis.com/auth/plus.login', 
    'profile', 
    'email', 
    'openid', 
)); 
+3

請編輯您的答案,以添加關於您的代碼如何工作的說明以及它如何解決OP的問題。許多SO海報是新手,不會理解你發佈的代碼。 –