0
嗯,我只是試圖更新我的劇本,我不斷收到的0一的getUser()返回PHP SDK 3.1.1和JS SDK的getUser()返回0
這裏是我改變
幾個片段舊代碼
<?php
require_once("src/facebook.php");
class cfb
{
public $fb;
public $_fb_user;
public $_fb_details;
public $_fb_app_id = '**************';
private $_fb_app_secret = '***************';
private $_user;
function __construct()
{
$this->fb = new Facebook(array(
'appId' => $this->_fb_app_id,
'secret' => $this->_fb_app_secret,
'cookie' => true,
));
$this->_fb_user = $this->fb->getSession();
$this->DB = new db();
$this->_user = new user();
}
public function session_exists()
{
// see if there is a session stored, if so make sure the session is still good on facebooks end
if($this->_fb_user) {
// test if session is still good
try
{
$me = $this->fb->api('/me');
}
catch(FacebookApiException $e){
error_log($e);
}
if(!empty($me)) {
return true;
}
} else {
return false;
}
}
新代碼
<?php
require_once("src/facebook.php");
class cfb
{
public $fb;
public $_fb_user;
public $_fb_details;
public $_fb_app_id = '*****************';
private $_fb_app_secret = '********************';
private $_user;
function __construct()
{
$this->fb = new Facebook(array(
'appId' => $this->_fb_app_id,
'secret' => $this->_fb_app_secret,
));
$this->_fb_user = $this->fb->getUser();
$this->DB = new db();
$this->_user = new user();
}
public function session_exists()
{
// see if there is a session stored, if so make sure the session is still good on facebooks end
if($this->_fb_user) {
// test if session is still good
try
{
$me = $this->fb->api('/me');
}
catch(FacebookApiException $e){
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
}
if(!empty($me)) {
return true;
}
} else {
return false;
}
}
這裏是我的js代碼
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $fb->_fb_app_id; ?>',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function(response) {
window.location="<?php echo $fbredirect; ?>";
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
我無法弄清楚。希望它是簡單的更新,但我猜不是=/
謝謝!你是否也知道如何使用新的JS SDK獲得「權限」? fb:login-button>在升級後不適用於我。 –
我試過改變燙髮「範圍」,但這不起作用 –
@ClintChaney,因爲v3.1.1使用getUser()而不是getSession(); – sonnb