2014-10-18 42 views
0

我正在使用Google OAuth2腳本,讓用戶使用他的Google +帳戶登錄。下面是代碼來獲得訪問令牌:未捕獲的異常'apiAuthException'帶有消息'錯誤提取OAuth2訪問令牌,消息:'invalid_grant''

require_once 'src/apiClient.php'; 
require_once 'src/contrib/apiPlusService.php'; 
$client = new apiClient(); 
$client->setApplicationName("Google+ Login Application"); 
$client->setScopes(array('https://www.googleapis.com/auth/plus.me')); 
$plus = new apiPlusService($client); 
if (isset($_GET['code'])) { 
    $client->authenticate(); 
    $_SESSION['access_token'] = $client->getAccessToken(); 
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); 
} 

config.php我設置客戶端ID和祕密如下:

'oauth2_client_id' => 'XYZ', 
'oauth2_client_secret' => 'ABC', 
'oauth2_redirect_uri' => 'http://example.com/gplus/index', 

當我通過谷歌+在重定向的時間,那麼帳戶登錄,下面我得到的例外:

Uncaught exception 'apiAuthException' with message 'Error fetching OAuth2 
access token, message: 'invalid_grant'' 

我看着在許多答案,但沒能得到解決,可以將部分明確告訴哪裏出了問題?

回答

1

我想通了。我使用的API本身存在問題。所以,我GOOGLE了更多,發現工作APi。 下面是鏈接,如果有人想

http://www.sanwebe.com/2012/11/login-with-google-api-php 

謝謝:)

相關問題