我已經得到了照片上傳功能,使用此代碼工作,Facebook的圖形API的照片上傳到粉絲專頁相冊
<?php
include_once 'facebook-php-sdk/src/facebook.php';
include_once 'config.php';//this file contains the secret key and app id etc...
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET_KEY,
'cookie' => true,
'domain' => 'your callback url goes here'
));
$session = $facebook->getSession();
if (!$session) {
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms'=>'user_photos,publish_stream,offline_access'//here I am requesting the required permissions, it should work with publish_stream alone, but I added the others just to be safe
));
echo 'You are not logged in, please <a href="' . $facebook->getLoginUrl() . '">Login</a> to access this application';
} else{
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$token = $session['access_token'];//here I get the token from the $session array
$album_id = 'the id of the album you wish to upload to eg: 1122';
//upload your photo
$file= 'test.jpg';
$args = array(
'message' => 'Photo from application',
);
$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);
}
}
?>
我希望這可以幫助,我和一個朋友砸我們的頭靠在牆上相當有一段時間才能得到這個工作!
無論如何,這裏是我的問題,我怎樣才能將圖片上傳到粉絲頁面?我很努力地做到這一點,當我上傳圖像時,我所得到的只是照片的ID,但沒有照片。
所以基本上,當用戶點擊我們應用程序上的上傳按鈕時,我需要它將他們創建的圖片上傳到我們的粉絲頁面的相冊中,並將它們標記在相冊上。
任何人都知道我可以做到這一點?
啊該死的...任何其他方式嘗試和鏈接到粉絲頁面的照片?有沒有辦法在上傳照片時對其進行標記? – Odyss3us 2010-06-18 10:37:37
目前無法基於頁面進行身份驗證。但FB在週二發佈了一個修復方案,可以解決這個問題。我希望修復也會創建上傳照片到頁面的權限。 http://bugs.developers.facebook.com/show_bug.cgi?id=10005(具體請參閱評論#85和#98) – gsharma 2010-06-18 22:26:11
讓我們希望他們做到正確! Thanx的答覆。 – Odyss3us 2010-06-22 07:06:07