簡體   English   中英

PHP SDK 3.1.1 和 JS SDK getUser() 返回 0

[英]PHP SDK 3.1.1 and JS SDK getUser() returning 0

好吧,我剛剛嘗試更新我的腳本,但 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 代碼中,在FB.init function 中添加oauth:true

You can see the PHP SDK v.3.1.1 working with the JS SDK in the example here: https://developers.facebook.com/blog/post/534/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM