Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

Unable to upload and tag photo on Facebook application using PHP?

I am trying to upload an image through php app.

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK , first of all you cant upload and tag photos at the same time. You need to upload the photo first then tag 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 the users on the image , but i found that i cant tag more than one friend at the same time so i had to loop through the array. Another thing the value of X & Y in the tag array is not the px , its the percentage so those values will 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 !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...