大家好,我是新手在php编程和facebook应用程序,我发现这段代码,它非常适合文字帖子,但我的要求是,我必须上传一张图片也,我尝试在arrey上添加‘源’=> '$image_source‘,但没有工作…如何上传照片?
<?php
include_once("config.php");
if($_POST)
{
//Post variables we received from user
$userPageId = $_POST["userpages"];
$userMessage = $_POST["message"];
$image_source = "http://www.example.com/image.jpg"
if(strlen($userMessage)<1)
{
//message is empty
$userMessage = 'No message was entered!';
}
//HTTP POST request to PAGE_ID/feed with the publish_stream
$post_url = '/'.$userPageId.'/feed';
//posts message on page statues
$msg_body = array(
'message' => $userMessage,
'source' => '$image_source'
);
if ($fbuser) {
try {
$postResult = $facebook->api($post_url, 'post', $msg_body );
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
}else{
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
header('Location: ' . $loginUrl);
}
//Show sucess message
if($postResult)
{
echo '<html><head><title>Message Posted</title><link href="style.css" rel="stylesheet" type="text/css" /></head><body>';
echo '<div id="fbpageform" class="pageform" align="center">';
echo '<h1>Your message is posted on your facebook wall.</h1>';
echo '<a class="button" href="'.$homeurl.'">Back to Main Page</a> <a target="_blank" class="button" href="http://www.facebook.com/'.$userPageId.'">Visit Your Page</a>';
echo '</div>';
echo '</body></html>';
}
}
?>发布于 2013-02-10 00:01:16
不能使用feed终结点发布照片。您应该使用具有publish_stream权限的/me/photos。要发布到相册,您需要/ALBUM_ID/photos端点
$msg_body = array(
'message' => $userMessage,
'source' => '@'.'$image_source'
);
$postResult = $facebook->api('/me/photos/','post', $msg_body);要使用与您的站点无关的urls,您需要使用url
$msg_body = array(
'message' => $userMessage,
'url' => 'http://somepage.com/img.png'
);https://stackoverflow.com/questions/14789608
复制相似问题