metrobalderas
metrobalderas

Reputation: 5240

Facebook API + php, photos.upload() not working?

I've set up a Facebook application, I've requested the extended permissions and now I'm trying to upload a photo but it doesn't work!

I've tried everything, from

$facebook->api_client->photos_upload('photo/789165784.jpg');

To

$facebook->api_client->photos_upload('photo/789165784.jpg', NULL, 'My photo', 100000287894654);

I'm beginning to suspect that I need to set up some extensions for php. I'm using WAMP and since the server is currently offline, I can't test it on production until tomorrow (I think..).

Thanks!

Upvotes: 2

Views: 5722

Answers (2)

Brody Robertson
Brody Robertson

Reputation: 8604

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

Upvotes: 3

Ben
Ben

Reputation: 68628

I don't know too much about this, I'm afraid, but the following link suggests that other people have had the same problem. Maybe this forum will be helpful:

http://forum.developers.facebook.com/viewtopic.php?pid=93450

It also links to this page, which seems like it might help:

http://wiki.auzigog.com/Facebook_Photo_Uploads

Ben

Upvotes: 2

Related Questions