Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload Photo To Album with Facebook's Graph API

Tags:

php

facebook

I'm trying to familiarize myself with Facebook's new Graph API and so far I can fetch and write some data pretty easily.

Something I'm struggling to find decent documentation on is uploading images to an album.

According to http://developers.facebook.com/docs/api#publishing you need to supply the message argument. But I'm not quite sure how to construct it.

Older resources I've read are:

  • http://wiki.auzigog.com/Facebook_Photo_Uploads

  • https://developers.facebook.com/docs/reference/rest/photos.upload/

If someone has more information or could help me tackle uploading photos to an album using Facebook Graph API please reply!

like image 316
st4ck0v3rfl0w Avatar asked Apr 27 '10 03:04

st4ck0v3rfl0w


People also ask

Is Facebook Graph API deprecated?

API Version Deprecations: As part of Facebook's Graph API and Marketing API, please note the upcoming deprecations: August 3, 2021: Graph API v3. 3 will be deprecated and removed from the platform. August 25, 2021 Marketing API v9.

Can you turn a Facebook post into an album?

You can't change a post's privacy without changing the privacy of the album. You can add photos to an album after you've posted them, but you can't move other types of posts. Note: You can upload up to 1000 photos to an album.


1 Answers

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

1 - Upload to 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.

$facebook->setFileUploadSupport(true); $args = array('message' => 'Photo Caption'); $args['image'] = '@' . realpath($FILE_PATH);  $data = $facebook->api('/me/photos', 'post', $args); print_r($data); 

2 - Upload to Target Album

This example will upload the photo to a specific album.

$facebook->setFileUploadSupport(true); $args = array('message' => 'Photo Caption'); $args['image'] = '@' . realpath($FILE_PATH);  $data = $facebook->api('/'. $ALBUM_ID . '/photos', 'post', $args); print_r($data); 
like image 65
Brody Robertson Avatar answered Oct 07 '22 17:10

Brody Robertson