0
我想在我的頁面上有兩個登錄按鈕。我對SDK的編碼不太熟悉,這可能嗎?Facebook PHP SDK V4:兩個登錄按鈕
一個按鈕正常工作,但第二個按鈕沒有。它只是將url更改爲index.php?code = wKdOAOLK ...而不登錄。
任何解決方法?
代碼:
// added in v4.0.0
require './facebook-sdk/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
use Facebook\GraphUser;
// start session
// init app with app id and secret
FacebookSession::setDefaultApplication('x','x');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://localhost/');
try {
$session = $helper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
// When Facebook returns an error
} catch(Exception $ex) {
// When validation fails or other local issues
}
// see if we have a session
if (isset($session)) {
...
}
按鈕,這兩個相同的代碼:
<?php echo '<a href="' . $helper->getLoginUrl() . '"><img src="facebook.png"></a>'; ?>
<?php echo '<a href="' . $helper->getLoginUrl() . '"><img src="facebook.png"></a>'; ?>
好的,這是有道理的。謝謝! –