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

Categories

Here is the code:

$file= 'bbbb.jpg';
$data = array(
            basename($file) => "@".realpath($file),
            "caption" => "Uploaded using graph api",
            "aid" => '13595',
            "access_token" => $accessToken,
            'method' => 'photos.upload'
);
$sds =$facebook->api($data);

This is the error

Uncaught CurlException: 26: failed creating formpost data

What to do?

See Question&Answers more detail:os

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

1 Answer

Here are some various ways to upload photos using the Graph API. The examples assume you've instantiated the $facebook object and have a valid session for the current user.

1 - Default Application Album of Current User

This example will upload the photo to your default application album of the current user. If the album does not yet exist it will be created.

$args = array('message' => 'Photo Caption');
$args['image'] = '@' . realpath($FILE_PATH);

$data = $facebook->api('/me/photos', 'post', $args);
print_r($data);

2 - Target Album

This example will upload the photo to a specific album.

$args = array('message' => 'Photo Caption');
$args['image'] = '@' . realpath($FILE_PATH);

$data = $facebook->api('/'. $ALBUM_ID . '/photos', 'post', $args);
print_r($data);

3 - Target Album with Access Token

This example will upload a photo to a specific album which requires an access token.

 $args = array('message' => 'Photo Caption');
$args['image'] = '@' . realpath($FILE_PATH);

$data = $facebook->api('/'. $ALBUM_ID . '/photos?access_token='. $ACCESS_TOKEN, 'post', $args);
print_r($data);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...