我需要使用应用程序在 Facebook 粉丝页面上发帖。我的帖子类型是文字+图片。当我只发布文本时,我没有问题,但是当我尝试添加 jpg 时它不起作用。
这是我的代码:
<pre>
<?php
require_once 'facebook.php';
// configuration
$appid = 'XXX';
$appsecret = 'YYY';
$pageId = 'ZZZ';
$msg = 'MSG MSG MSG';
$title = 'TITOLO TITOLO TITOLO';
$uri = 'http://www.google.it/';
$desc = 'Description';
$pic = 'http://sharefavoritebibleverses.com/images/bible_verses.png';
$action_name = 'AZIONE NOME';
$action_link = 'http://www.yahoo.it';
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'cookie' => false,
));
$user = $facebook->getUser();
// Contact Facebook and get token
if ($user)
{
// you're logged in, and we'll get user acces token for posting on the wall
try
{
$facebook->setFileUploadSupport(true);
$page_info = $facebook->api("/$pageId?fields=access_token");
if (!empty($page_info['access_token'])) {
/*$attachment = array(
'access_token' => $page_info['access_token'],
'message' => $msg,
'name' => $title,
'picture'=>$pic
);*/
$photo_details = array(
'message' => 'message',
'access_token' => 'XYZ'
);
$photo_details['picture'] = '@'.realpath('aaa.jpg');
echo realpath('aaa.jpg');
$status = $facebook->api("/$pageId/feed", "post", $photo_details);
}
else
{
$status = 'No access token recieved';
}
}
catch (FacebookApiException $e)
{
error_log($e);
$user = null;
}
}
else
{
// you're not logged in, the application will try to log in to get a access token
header("Location:{$facebook->getLoginUrl(array('scope' => 'photo_upload,user_status,publish_stream,user_photos,manage_pages'))}");
}
echo $status;
echo "<br>CONT=".count($status);
?>
我也需要像第二种格式,而不是第一种格式:
我的代码有什么问题?
谢谢!