新的PHP請原諒我愚蠢的問題。Facebook:php上傳照片和張貼在牆上
我正在創建我的第一個fb應用程序。它允許用戶瀏覽他們的本地驅動器並選擇一張照片。一旦提交,它將重定向到下一頁並處理到存儲到我的服務器上,然後張貼到用戶的牆上。
這個應用程序並沒有太多的工作。用戶瀏覽和將照片存儲到我的服務器上的部分正在工作,但無法從我的服務器中取回照片並將其張貼到用戶的牆上。
的config.php:
<?php
require_once 'facebook.php';
$app_id = "";
$app_key = "";
$app_secret = "";
$canvas_url = "";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$session = $facebook->getSession();
if (!$session) {
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'publish_stream, user_photos, read_stream, read_friendlists'
));
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
}//end if session user
else
{
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$updated = date("l, F j, Y", strtotime($me['updated_time']));
echo "Hello " . $me['name'] . "<br />";
echo "You last updated your profile on " . $updated . "<br />" ;
echo "<img src='https://graph.facebook.com/".$uid."/picture'/>";
}//end try getUser
catch (FacebookApiException $e) {
echo "Error:" . print_r($e, true);
}//end catch getUser
}//end else user
index.php文件包含表單:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
uploader.php運行過程
$target_path = "uploads/";
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['uploadedfile']['name']).
" has been uploaded" . "<br />";
} else{
echo "There was an error uploading the file, please try again!" . "<br />";
}
try {
$post_id = $facebook->api("/".$uid."/feed", "post", array("picture"=>$target_path));
if(isset($post_id))
echo "A new post to your wall has been posted with id: $post_id";
} catch (FacebookApiException $e) {
error_log($e);
}
我一直在嘗試許多不同的方法,其我可以在網上找到,但它不起作用。我曾嘗試添加$ facebook-> setFileUploadSupport(true);但收到錯誤。
請指教我如何才能將照片上傳到用戶牆上。 非常感謝您
難道不是Facebook已經讓你這樣做? – Benubird 2011-03-02 17:07:03
我想創建一個應用程序,他們將能夠通過它上傳照片。然後,照片將張貼到牆上,併發送到我的服務器。我會抓住這些照片,然後將它們顯示爲拼貼畫。 – meAtStackOverflow 2011-03-03 04:11:40