webhost

Web hosting
Showing posts with label facebook. Show all posts
Showing posts with label facebook. Show all posts

Friday, March 23, 2012

Facebook FQL query using graph api

we can run facebook FQL  query using the graph api.
Here example to get facebook photos from facebook album
First we need to include the facebook class then create an object of facebook class
by using a simple example of FQL query we get an array of details of photos of particular album

require '../src/facebook.php';

 $facebook = new Facebook(array(
  
'appId'  => '...',
  
'secret' => '...'));

function get_photos_by_album_id($album_id){

if(
$album_id)
        
$fql            =   'SELECT pid,src_big,owner,link,position,created,caption,src FROM photo WHERE aid="'.$album_id.'"';
           
                
$param  =   array(
                
'method'    => 'fql.query',
                
'query'     => $fql,
                
'callback'  => ''
            
);
            
$fqlResult   =   $facebook->api($param);
    return 
$fqlResult;

}

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