PHP SDK 3.1.1和JS SDK getUser()返回0
我刚刚尝试更新脚本,但getUser()的返回值一直为0 以下是我更改的几个片段 旧代码PHP SDK 3.1.1和JS SDK getUser()返回0,php,facebook,Php,Facebook,我刚刚尝试更新脚本,但getUser()的返回值一直为0 以下是我更改的几个片段 旧代码 在JS代码中,在FB.init函数中添加oauth:true 您可以在这里的示例中看到PHP SDK v.3.1.1与JS SDK一起工作:谢谢!您还知道如何让“perms”与新的JSSDK一起工作吗?升级后对我无效。@ClintChaney,因为v3.1.1使用getUser()而不是getSession(); <?php require_once("src/facebook.php"); c
在JS代码中,在FB.init
函数中添加oauth:true
您可以在这里的示例中看到PHP SDK v.3.1.1与JS SDK一起工作:谢谢!您还知道如何让“perms”与新的JSSDK一起工作吗?升级后对我无效。@ClintChaney,因为v3.1.1使用getUser()而不是getSession();
<?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;
}
}
<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>