問題がわかりません。https://developers.facebook.com/docs/php/howto/postwithgraphapi/のチュートリアルに従いました。
しかし、ユーザーのウォールにリンクを投稿することはできません。以下は私のコードです:
<?php
error_reporting(E_ALL); ini_set('display_errors', 'On');
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'XXX',
'secret' => 'XXXXX',
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if($user) {
try {
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!'
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
// Give the user a logout link
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl(array(
'scope' => 'publish_stream'
));
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, so print a link for the user to login
// To post to a user's wall, we need publish_stream permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
echo 'No user...Please <a href="' . $login_url . '">login.</a>';
}
?>
エラー報告を有効にしましたが、エラーを表示できません。出力は常に次のとおりです。
"ログインしてください。"
リンクをクリックすると、facebook からリダイレクトされた後、再び同じメッセージが表示されます。