Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tag a user in a photo using the Facebook Graph API?

I tried:

$args = array(
  'access_token' => $access_token,
  'id' => $uid
);

$url = "https://graph.facebook.com/{$idPhoto}/tags";

$ch = curl_init();
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);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$data = curl_exec($ch);

It has returned me:

{"error":{"type":"QueryParseException","message":"Unknown path components: \/tags"}}

It does not seem possible because its not in the Facebook documentation:

http://developers.facebook.com/docs/api#publishing

Can someone confirm me that it's not possible to tag a user in a recently uploaded photo?

like image 926
FR6 Avatar asked Jun 10 '10 19:06

FR6


1 Answers

Uploading image and tagging multiple people in one step using PHP Facebook Graph API:

$args = array(
  'message' => 'Message',
  'image'   => '@' . realpath($path_to_image),
  'tags'    => array(
     array(
      'tag_uid'=> $friend1_uid,
      'x'      => $x1,
      'y'      => $y1,
     ),
     array(
      'tag_uid' => $friend2_uid,
      'x'       => $x2,
      'y'       => $y2,
     ),/*...*/
   ),
);

$data = $facebook->api('/me/photos', 'post', $args);

Where $facebook is initialized Facebook PHP SDK object. $data['id'] is id of uploaded photo.

Notes: 1. fileUpload option has to be set when initializing Facebook object:

$facebook = new Facebook(array(
  /*..*/
  'fileUpload'  => true,
));
  1. publish_stream permission has to be granted;
like image 138
Andrius Avatar answered Oct 27 '22 01:10

Andrius