0

I try to use the tagging function in the Facebook API, but it does not work.

This is the permission code:

$facebook->getLoginUrl(
    array(
        'canvas' => 1,
        'fbconnect' => 0,
        'req_perms' => 'user_photos, friends_photos, publish_stream,
                        offline_access, user_likes, user_photo_video_tags',
        'next' => $appCanvasPage.'index.php',
        'cancel_url' => $appCanvasPage
    )
);

This is the first method I tried:

$photoId = $userid."_".$upload_photo['id'];
$post_url = "https://graph.facebook.com/"
            .$$photoId . "/tags/" . $friendid
            . "?access_token=". $access_token
            . "&x=" . $x_coordinate 
            . "&y=" . $y_coordinate 
            . "&method=POST";
file_get_contents($post_url);

This returns an error:

"message": "Unsupported post request.",
"type": "GraphMethodException",
"code": 100

Second method I have tried:

$fd = 'XXXX';
$tag = array(
    'tag_uid' => $fd,
    'x' => '10.0',
    'y' => '10.0'
);
$tags = array($tag0);
$facebook->api(
    array(
        'method' => 'photos.addTag',
        'pid' => $photoId,
        'tags' => json_encode($tags)
    )
);

This code does not tag the photo either.

Cheesebaron
  • 24,131
  • 15
  • 66
  • 118

3 Answers3

1

ok..i found the solution..can use this code to do tagging

$tag = array(
            'tag_uid' => $fb->getUser(),
            'x' => 0,
            'y' => 0
        );
        $tags[] = $tag;
        $image = array(
            'access_token' => $session['access_token'],
            'tags' => $tags,
        );
        $fb->setFileUploadSupport(true);
        $image['image'] = '@'.realpath($image_path);
        $fb->api('/me/photos', 'POST', $image);
0

photos.addTag is an old legacy REST API. you should call something like this:

$fd = 'XXXX';
$tag0 = array('to' => $fd, 'x' => '10.0', 'y' => '10.0');
$tags = array($tag0);
$facebook->api('/' . $photoId . '/tags', 'POST', $tags);
mask8
  • 3,560
  • 25
  • 34
  • no error appear..but the picture not tagging and the code stop there..no footer after that code... – user1536721 Jul 19 '12 at 06:20
  • _“no footer after that code...”_ – that most likely means you have an error in your script, so it breaks. Set you error_reporting and display_errors to sensible levels in your PHP config, so that PHP can show you the reason for that error. – CBroe Jul 19 '12 at 11:57
0
$post_url = "https://graph.facebook.com/"
        .$$photoId . "/tags/" . $friendid

You should really do some debugging instead of just “wondering” why things fail …

You have written $$photoId there, with two $ signs. That’s what’s called “variable variables” in PHP, and would try to access a variable which name is the content of $photoId – but I’d suspect you do not have a variable called “$someuserid_somepictureid” set in your script.

So apart from giving an error (if you had set up your error_reporting to something sensible, like I already told you), if you had just made a debug output of $post_url you could have easily spotted that there is something wrong with it …

CBroe
  • 91,630
  • 14
  • 92
  • 150
  • that is not an error cause the response "message": "Unsupported post request.", which is the post method is not correct..the code is just a typo.. i already declare the picture id as userid_photoid – user1536721 Jul 20 '12 at 16:06
  • Of course that leads to an error, because then the API address you try to connect to will be something like `https://graph.facebook.com//tags/1234567890`, and _of course_ you’ll get an _“unsupported post request”_ message for that, because it’s just a nonsense address … – CBroe Jul 20 '12 at 17:51
  • nvm..i just found the solution.. :) – user1536721 Jul 21 '12 at 19:06