我正在创建一个Facebook应用程序。我试着发布用户wall.But我没有得到任何回复
php code
$user = $facebook->getUser();
if($user == 0) {
$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));
echo ("<script> top.location.href='".$login_url."'</script>");
} else { $token=$facebook->getAccessToken();
try {
params = array(
'message' => "Hurray! This works :)",
'name' => "This is my title",
'caption' => "My Caption",
'description' => "Some Description...",
'link' => "http://stackoverflow.com",
'picture' => "http://i.imgur.com/VUBz8.png",
);
$post = $facebook->api("/me/feed","POST",$params);
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}
}
我无法将内容发布到用户的墙上。请任何人帮我调试代码
答案 0 :(得分:0)
试试这个,我使用以下内容在我的FB上成功发布:
$user = $facebook->getUser();
if($user == 0) {
//$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));
//echo ("<script> top.location.href='".$login_url."'</script>");
} else { $token=$facebook->getAccessToken();
try {
$post = $facebook->api("/me/feed","POST",array(
'message' => "Hurray! This works :)",
'name' => "This is my title",
'caption' => "My Caption",
'description' => "Some Description...",
'link' => "http://stackoverflow.com",
'picture' => "http://i.imgur.com/VUBz8.png"
));
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}
}
如果您还没有,请记住包含facebook.php api和您的代码类初始化
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
'cookie' => true
));
答案 1 :(得分:0)
尝试使用php curl发布。如果使用rest api工作你的facebook课程。 Rest api最近删除了。
$user = $facebook->getUser();
if($user == 0) {
$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));
echo ("<script> top.location.href='".$login_url."'</script>");
} else { $token=$facebook->getAccessToken();
try {
$params = array(
'access_token' => $token,
'message' => "Hurray! This works :)",
'name' => "This is my title",
'caption' => "My Caption",
'description' => "Some Description...",
'link' => "http://stackoverflow.com",
'picture' => "http://i.imgur.com/VUBz8.png",
);
$url = 'https://graph.facebook.com/'.$user.'/feed';
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true
));
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}
}
你的代码中的params不是$ params。