繼Post to users wall upon facebook app submission(我的老問題),我想出了下面的代碼,但它似乎並沒有工作?我認爲最好能夠提出一個新問題,因爲這是一個新問題。從Facebook用戶獲得許可併發布到他們的牆上
我在做什麼錯?另外,這個代碼應該放在哪裏?
<?php
$session = $facebook->getSession();
//Is user logged in and has allowed this app to access its data
if (!$session) {
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'next' => 'enter.php',
'cancel_url' => 'index.php',
));
// use the $loginUrl created on the enter button to request permission;
}
$user_id = $facebook->getUser();
//post to wall
$attachment = array('message' => '<message>',
'name' => '<name here>',
'caption' => '<caption here>',
'link' => '<link to app>',
'description' => '<enter description >',
'picture' => '<enter image url>',
'actions' => array(array('name' => '<enter action label>',
'link' => '<enter action url>')
);
$permissions = $facebook->api("/me/permissions");
if(array_key_exists('publish_stream', $permissions['data'][0])) {
// Permission is granted!
// Do the related task
try {
$post_id = $facebook->api('/me/feed', 'post', $attachment);
} catch (CurlException $e) {
//timeout so try to resend
$post_id = $facebook->api('/me/feed', 'post', $attachment);
}
catch (FacebookApiException $e) {
error_log($e);
}
} else {
// We don't have the permission
// Alert the user or ask for the permission!
}
// store the post id in-case you need to delete later
?>
感謝嗨,什麼權限才能生成訪問令牌,我需要張貼到其他用戶牆? –