Can't upload and tag a photo in a Facebook application using PHP?

I am trying to upload an image through a php application.

Error :-

Uncaught CurlException: 26: failed creating formpost data thrown in

base_facebook.php on line 814

My code: -

$pic='img/'.$fbid.'.jpg'; 



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

imagedestroy($image);
-2
source share
1 answer

OK, first of all, you cannot upload and tag photos at the same time. First you need to upload a photo, and then mark it. So the code will be

$args = array('message' => 'Testing photo tagging');
$args['image'] = '@' . realpath($FILE_PATH);
$data = $facebook->api('/me/photos', 'post', $args);

then we have to tag users in the image, but I found that I cannot tag more than one friend at a time, so I had to iterate over the array. Another thing is that the value of X and Y in the tag array is not px, its percentage value, so that these values ​​do not exceed 100

$photo_id = $data['id'];
$tags = array(

    array(
        'tag_uid' => 1337904214,
        'tag_text' => 'Joy',
        'x' => 50,
        'y' => 30
    ),
    array(
        'tag_uid' => 709019872,
        'tag_text' => 'test',
        'x' => 100,
        'y' => 100
    )
);

foreach($tags as $t) {
    $t = array($t);
    $t = json_encode($t);
    try {
        $facebook->api('/' . $photo_id . '/tags', 'post', array('tags' => $t));
    } catch (Exception $e) {
        print_r($e);
    }
}

Good luck

+2
source

All Articles