0
我在Facebook上創建了一個應用程序,並通過PHP SDK 4.0創建了登錄,我需要對該提要擁有寫權限,但是即使我已經添加了權限,不記錄更多的窗口框來批准和授予權限。SDK 4.0 Facebook,沒有對話框來請求權限publish_actions
這是所使用的代碼:
<?php session_start();
require 'Facebook/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphObject;
use Facebook\FacebookRequestException;
use Facebook\FacebookRedirectLoginHelper;
// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('XXXXXXXXXX XXXXXXXX','XXXXXXXXXXXXXXXXXX');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('XXXXXXXXXXXXX');
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)) {
// graph api request for user data
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
// print data
echo print_r($graphObject, 1);
if($session) {
try {
$response = (new FacebookRequest(
$session, 'POST', '/me/feed', array(
'link' => 'www.example.com',
'message' => 'User provided message'
)
))->execute()->getGraphObject();
echo "Posted with id: " . $response->getProperty('id');
} catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}
} else {
$params = array(
scope => 'publish_actions'
//redirect_uri => $url
);
// show login url
echo '<a href="' . $helper->getLoginUrl($params) . '">Login</a>';
}
?>
如果你能夠粘貼代碼片段而不是冗長的代碼,那將會很好。這使我們能夠更有效地理解您的代碼。 – Roylee 2014-09-03 07:04:46
如果您以前的成功登錄中沒有包含'publish_actions'的會話,那麼您的代碼將無法再次輸出(新)登錄URL ......您不僅應該檢查您是否擁有有效用戶會話,而且如果您已經擁有必要的權限 - 並且如果其中一個失敗,則需要再次通過登錄流程發送用戶。 (你也應該考慮文檔中關於再次請求權限的內容,以前已經被用戶拒絕了) – CBroe 2014-09-03 08:42:23
嗨@CBroe請你分享一個鏈接,在那裏再次詢問拒絕的權限? – 2014-12-17 01:12:42