我試圖在我的控制器中發佈一個相冊到Facebook的功能。每次訪問函數時,我都會重定向到REDIRECT_URI,就好像$ userid = 0,即使我剛剛正確登錄到Facebook。這是因爲登錄後,它重新啓動該功能,並創建一個新的Facebook會話,消滅我剛剛得到的用戶?功能的Facebook身份驗證 - getUser()返回0
感謝您提供的任何幫助。
function share($id){
if (!$id) { $this->Session->setFlash(__('Invalid id for Album', true));
$this->redirect(array('action'=>'index')); }
$photos = $this->Album->find('all', array('conditions' => array('Album.id' => $id)));
$facebook = new Facebook(array('appId'=>'valid aphid', 'secret'=>'valid secret'));
$facebook->setFileUploadSupport(true);
$userid = $facebook->getUser();
if($userid) {
try {
$user_profile = $facebook->api('/me'); // Gets User's information based on permissions the user has granted to your application.
}
catch(FacebookApiException $e){
error_log($e);
// Print results if you want to debug.
$userid = null;
}
} else {
$login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI,'scope' => PERMISSIONS_REQUIRED));
echo ("<script> top.location.href='".$login_url."'</script>");
}
//Create album
$results = $facebook->api('me/albums', 'post', $photos[0]['Album']['name']);//->photos_createAlbum($albumname, '', '', 'everyone', $this->_userid);
}
[爲什麼Facebook PHP SDK getUser總是返回0?](http://stackoverflow.com/questions/6790272/why-is-facebook-php-sdk-getuser-always-returning-0) –