2

I use this codes , but I get an error

Fatal error: Uncaught OAuthException: (#121) Invalid photo id thrown in /home/a283357/public_html/app/base_facebook.php on line 1106

MY codes are for tags

$data = array(array('tag_uid' => $friends, 'x' => rand() % 100, 'y' => rand() % 100 ));
$data = json_encode($data);
//, 'tags' => $data,


$photo_details = array( 'message'=> 'message ', 'tags' => $data, 'image' => '@' . realpath($file) );
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);

And I want to tags 5 or 10 friends

Chris Farmer
  • 23,314
  • 32
  • 110
  • 161
Ai Bossi
  • 21
  • 1
  • 4

1 Answers1

2

You cannot specify the tags for photo while creating it. Also you using wrong names for parameters used in create photo method.

You should create the photo first and then tag it.

Create photo:

$photo_details = array(
  'message'=> 'message ',
  'source' => '@' . realpath($file)
);
$uploaded_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);

Now tag it:

$tags = array(
  array('tag_uid' => $friend_id, 'x' => rand() % 100, 'y' => rand() % 100 )
);
$photo_id = $uploaded_photo['id'];
$facebook->api('/'.$photo_id.'/tags', 'post', array('tags'=>$tags));

BEWARE, documentation states to parameter as one to specify the tagged user, but it's not (it's tag_uid as in your initial sample).

Juicy Scripter
  • 25,035
  • 5
  • 70
  • 90
  • I get this error Fatal error: Uncaught OAuthException: (#803) Some of the aliases you requested do not exist: Array thrown in /home/a283357/public_html/app/base_facebook.php on line 1106 – Ai Bossi Apr 11 '12 at 15:21
  • @AiBossi, there was a mistake in code sample that should be fixed now. – Juicy Scripter Apr 11 '12 at 15:53
  • again error Fatal error: Uncaught OAuthException: (#100) Invalid keys "to" were found in param "tags". thrown in /home/a283357/public_html/app/base_facebook.php on line 1106 – Ai Bossi Apr 11 '12 at 16:07
  • Again show Fatal error: Uncaught OAuthException: (#121) Invalid photo id thrown in /home/a283357/public_html/app/base_facebook.php on line 1106 – Ai Bossi Apr 14 '12 at 15:12
  • @AiBossi, sample code doesn't contain any error handling ensure the second request for tagging photo contain correct `id` of photo. You may want to `print_r($uploaded_photo)` before tagging the photo. For me it's perfectly working that way. – Juicy Scripter Apr 14 '12 at 16:52
  • @AiBossi, what do you mean by "second time"? Every request for tagging photo should be done to `https://graph.facebook.com/PHOTO_ID/tags` if you want to tag photo you didn't uploaded you need to know the `id` of photo. – Juicy Scripter Apr 15 '12 at 13:32
  • The problem is about photo id .When I use https://graph.facebook.com/414030735274837/ show false .Something wrong with photo id – Ai Bossi Apr 15 '12 at 19:53
  • You should be able to access the photo of user/friends with `access_token` of user who granted `user_photos`/`friends_photos` permission. – Juicy Scripter Apr 15 '12 at 20:36