webhost

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,
                                   publish_stream,
                                   user_birthday,
                                   read_stream,
                                   photo_upload,
                                   user_photos,
                                   user_photo_video_tags,
                                 );
echo "<script type="text/javascript">
top.location.href = '
$loginUrl';
// ]]></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:

 <?php
$facebook->setFileUploadSupport(true);

//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
$album_uid 
$create_album['id'];
  
//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