Search code examples
facebookfacebook-graph-apitagging

Can't tag photo with Facebook API


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.


Solution

  • 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);