Web hosting

Wednesday, March 21, 2012

Create photo albums and upload photos using the Facebook

By using Facebook graph API allow us to access public information like user's first name, last name and profile picture are publicly available. To get additional access like upload photos,create albums,you must first get their permission.

The code example assumes that you have already generated an authenticated session while generating the loginUrl we need to specify scope for the permission (photo_upload, user_photos)

 require '../src/facebook.php';$facebook = new Facebook(array(
'appId'  => '...',
'secret' => '...'));$loginUrl=$facebook->getLoginUrl( array(
'scope'         'email,
echo "<script type="text/javascript">
top.location.href = '
// ]]></script>";?>

 permission popup once we get the permission from user we can able to upload the photos to there albums

The following snippet creates a photo album and then uploads a photo into it:


//Create an album
$album_details = array(
message'=> 'Album desc',
name'=> 'Album name'
$create_album = $facebook->api('
/me/albums', 'post', $album_details);

//Get album ID of the album you'
ve just created
//Upload a photo to album of ID...$photo_details = array(
'message'=> 'Photo message');$file='app.jpg'//Example image file$photo_details['image'] = '@' realpath($file);
$upload_photo $facebook->api('/'.$album_uid.'/photos''post'$photo_details);?>

 Supported Image Types You can upload the following image file formats through this call: *GIF *JPG *PNG *PSD *TIFF *JP2 *IFF *WBMP *XBM Facebook SDK

No comments:

Post a Comment