我想問一下使用FB API(Graph或REST)標記照片是否可以/如何。如何在facebook-api中標記照片?
我已經設法創建了一個相冊,同時也上傳了一張照片,但我堅持標記。
我有權限和正確的會話密鑰。
我的代碼至今:
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$token = $session['access_token'];//here I get the token from the $session array
$album_id = $album[0];
//upload photo
$file= 'images/hand.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));
$search = array('{"id":', "}");
$delete = array("", "");
// picture id call with $picture
$picture = str_replace($search, $delete, $data);
//here should be the photos.addTag, but i don't know how to solve this
//above code works, below i don't know what is the error/what's missing
$json = 'https://api.facebook.com/method/photos.addTag?pid='.urlencode($picture).'&tag_text=Test&x=50&y=50&access_token='.urlencode($token);
$ch = curl_init();
$url = $json;
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_exec($ch);
} catch(FacebookApiException $e){
echo "Error:" . print_r($e, true);
}
我真的搜查了很長一段時間,如果你知道的東西,可能會幫助我,請在這裏發表吧:) 感謝您的幫助, 卡米洛
是你能夠讓它通過測試控制檯的工作?它返回什麼錯誤? http://developers.facebook.com/docs/reference/rest/photos.addTag – serg 2010-08-14 17:40:52
它返回「121無效的照片ID」 我已經搜索了一整天只爲了這一點,但似乎該方法已經消失/破碎/棄用... 如果有人知道解決方案,將不勝感激。 謝謝, 卡米洛 – Camillo 2010-08-14 17:49:34
它不會在所有的工作,無論是從瀏覽器直接調用,也不由試驗檯,也不由捲曲...... 我對此很傷心,我很喜歡這個主意整合?此爲我的應用程序:( 順便說一句謝謝你的回答, 卡米洛 – Camillo 2010-08-14 17:52:32