我想上傳一張照片粉絲頁面Feed,但我不能,我讀過一次發送它,必須是POST FORM !這是正確的?Facebook錯誤:「創建formpost數據失敗」上傳照片到粉絲頁面
的index.php
<html>
<head>
<title>Index Page Facebook</title>
</head>
<body>
<?php
require('config.php');
if($user){
$_SESSION['user_id'] = $user;
?>
<form action="facebook3.php" method="post" accept-charset="utf-8">
Message <input type="text" name="message"> <br>
Photo: <input type="file" name="pictureFile">
<input type="submit" value="Postar">
</form>
<?php
exit();
}else{
?>
<a href="<?php $facebook->getLoginUrl(array('scope' => $fbPermissions, 'redirect_uri' => $homeurl)); ?>">Login Facebook</a>;
<?php
}
?>
</body>
</html>
fb.php
<?php
include_once("config.php");
//destroy facebook session if user clicks reset
if($_POST)
{
//$loginUrl = $facebook->getLoginUrl(array('scope' => 'manage_pages'));
//$loginUrl = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
@include_once("config.php");
//Post variables we received from user
$userPhoto = $_FILES["pictureFile"]["tmp_name"];
$userMessage = $_POST["message"];
if(strlen($userMessage)<1)
{
//message is empty
$userMessage = '';
}
//HTTP POST request to PAGE_ID/photos with the publish_stream
$post_url = '/228433913910358/feed';
//posts message on page statues
$msg_body = array(
'source'=>'@'.$userPhoto,
'message' => $userMessage
);
if ($user) {
try {
$postResult = $facebook->api($post_url, 'post', $msg_body);
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
}else{
header("Location: index.php ");
}
//Show sucess message
if($user && !empty($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/'.$fbuser.'">Visit Your Page</a>';
echo '</div>';
echo '</body></html>';
}
}
?>
所以,我已經嘗試過通過郵寄,直接寫路徑$照片,但錯誤依然存在!
未能創造formpost數據
調用Twitter的,當我面臨同樣的問題API庫。在這種情況下是庫中的一行,它執行php curl_exec指令觸發該消息。很可能您調用的Facebook API庫使用相同的指令,並且出於同樣的原因失敗 – Pablo