好的,所以下面的鳕鱼基本上可以正常工作,当这条线是这样的:
$post_url = '/'.$userPageId.'/feed';
这成功发布到 Facebook 页面时间轴。但我想上传一张照片,当我把这行改成
$post_url = '/'.$userPageId.'/photos';
它发布照片......但它发布到用户提要,而不是作为 Facebook 页面。
我希望这可以将照片发布到 Facebook 页面时间轴
[配置.php]
<?php
include_once("inc/facebook.php");
##################################
//Call Facebook API
// Required facebook permissions
$fbPermissions = 'publish_stream,manage_pages,photo_upload';
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret,
'fileUpload' => true,
'cookie' => true
));
$fbuser = $facebook->getUser();
?>
[进程.php]
<?php
include_once("config.php");
if($_POST)
{
//Post variables we received from user
$userPageId = $_POST["userpages"];
$userMessage = $_POST["message"];
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.'/photos';
//posts message on page statues
$msg_body = array(
'source' => '@' . 'test.jpg',
'message' => "yo yo yo",
);
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)
{
}
}
?>
[index.php](用于登录)
<?php
include_once("config.php");
if ($fbuser)
{
try {
$user_profile = $facebook->api('/me');
//Get user pages details using Facebook Query Language (FQL)
$fql_query = 'SELECT page_id, name, page_url FROM page '
.'WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid='
.$fbuser.')';
$postResults = $facebook->api(
array( 'method' => 'fql.query', 'query' => $fql_query )
);
} catch (FacebookApiException $e) {
echo $e->getMessage();
$fbuser = null;
}
} else {
//Show login button for guest users
$loginUrl = $facebook->getLoginUrl(
array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions)
);
echo '<a href="'.$loginUrl.
'"><img src="images/facebook-login.png" border="0"></a>';
$fbuser = null;
}
if($fbuser && empty($postResults))
{
/*
if user is logged in but FQL is not returning any pages, we need to make
sure user does have a page OR "manage_pages" permissions isn't granted yet
by the user. Let's give user an option to grant permission again.
*/
$loginUrl = $facebook->getLoginUrl(
array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions)
);
echo '<br />Could not get your page details!';
echo '<br /><a href="'.$loginUrl.'">Click here to try again!</a>';
}
elseif ($fbuser && !empty($postResults))
{
//Everything looks good, show message form.
}
?>