我想问一下使用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