我試圖實現一種方式讓用戶使用Google和Facebook作爲大學作業的一部分登錄。我有我的「與Google登錄」代碼很好地工作。然後我開始嘗試實現我的「使用Facebook代碼登錄」。使用臉書登錄/谷歌PHP衝突
<?php
//required files for Google+ login
require_once 'google-api-php-client/src/apiClient.php';
require_once 'google-api-php-client/src/contrib/apiPlusService.php';
//include this file containing specific app details (key, clientID, redirect etc) and get user details (image and name in this case)
include 'php/googleplus.php';
//required for facebook login
require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxx',
'secret' => 'xxxx',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
?>
........ ........
<?php if ($user):
$fblogoutUrl = $facebook->getLogoutUrl();
?>
<a href="<?php echo $fblogoutUrl; ?>">Logout</a>
<?php else:
$fbloginUrl = $facebook->getLoginUrl();
?>
<div>
Login using OAuth 2.0 handled by the PHP SDK:
<a href="<?php echo $fbloginUrl; ?>">Login with Facebook</a>
</div>
<?php endif ?>
<div id="login">
<!--Load the php code that contains the user login options for google-->
<?php
include 'php/userlogin.php';
?>
我沒有太多可言據我可以告訴改變的代碼 - 只加我自己的應用程序ID,祕密和重定向。當我點擊「使用Facebook登錄」鏈接時,我收到以下錯誤消息:
**Fatal error**: Uncaught exception 'apiAuthException' with message 'Error fetching OAuth2 access token, message: 'invalid_grant'' in /Applications/MAMP/htdocs/www/Shared sites/LOGIN ASSIGNMENT/google-api-php-client/src/auth/apiOAuth2.php:105 Stack trace: #0 /Applications/MAMP/htdocs/www/Shared sites/LOGIN ASSIGNMENT/google-api-php-client/src/apiClient.php(138): apiOAuth2->authenticate(Array) #1 /Applications/MAMP/htdocs/www/Shared sites/LOGIN ASSIGNMENT/php/googleplus.php(19): apiClient->authenticate() #2 /Applications/MAMP/htdocs/www/Shared sites/Login Assignment/index.php(7): include('/Applications/M...') #3 {main} thrown in **/Applications/MAMP/htdocs/www/Shared sites/LOGIN ASSIGNMENT/google-api-php-client/src/auth/apiOAuth2.php** on line **105**
顯然是由於某種原因試圖訪問Google php文件。我沒有足夠的經驗來診斷問題。我想知道是否有其他人遇到這個錯誤,我將如何解決這個問題,謝謝。
能否請您刪除您的谷歌執行和Facebook只是嘗試一下呢? – 2012-04-28 13:32:04
我現在要做的就是回到你身邊 - 這可能需要我一點時間。 – garethdn 2012-04-28 13:33:05
好吧,我已經刪除了谷歌的東西登錄。當我最初點擊「使用Facebook登錄」鏈接時,我沒有看到Facebook的權限彈出窗口 - 我的鏈接立即更改爲「註銷」。我不知道這是否是緩存問題?無論哪種方式,我都沒有收到來自我的OP的錯誤消息。 – garethdn 2012-04-28 13:54:59