你能告訴我我做錯了什麼。我使用PHP。嘗試將照片上傳到用戶個人資料..我獲得權限,它的工作原理。但上傳不起作用,我嘗試了很多方法。那麼我做錯了什麼?FB開發 - 上傳一張照片到用戶的個人資料
<?php
include_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'ID',
'secret' => 'SECRET',
'cookie' => true,
'domain' => 'DOMAIN',
'fileUpload' => 'true'
));
$session = $facebook->getSession();
if (!$session) {
$loginUrl = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 1,
'display' => 'page',
'req_perms' => 'user_likes, publish_stream',
'next' => 'NEXTURL'
));
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
} else{
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$token = $session['access_token'];//here I get the token from the $session array
$album_id = 'ALBUM ID'; /// what should I write here?
//upload your photo
$file= 'logo.png';
$args = array(
'message' => 'Photo from app',
);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/'.$album_id.'/photos?access_token='.$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
//returns the id of the photo you just uploaded
print_r(json_decode($data,true));
} catch(FacebookApiException $e){
echo "Error:" . print_r($e, true);
}
}
?>
在此先感謝
定義「不工作」。您是否看到錯誤,警告,其他輸出 –
沒有錯誤..首先用戶點擊「轉到應用程序」,然後給出publish_stream權限,然後瀏覽器被重定向到絕對清空/空的php頁面。你能告訴我,我應該寫1)$ album_id; 2)$ file ='logo.png'; < - 是否正確?我應該在這裏提到照片的網址嗎?在此先感謝 –