webhost

Web hosting
Showing posts with label php. Show all posts
Showing posts with label php. 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

Tuesday, February 21, 2012

HTTP POST Using PHP CURL

Here's how you execute a POST using the PHP CURL library.

//define post values 
$message="test message ";//define post url
 
$url="http://localhost/WebServices/";//encode the message
 
$message urlencode($message);//initialize the curl
 
$ch curl_init();

 if (!
$ch){
die(
"Couldn't initialize a cURL handle");
}
//setting options
 
$ret curl_setopt($chCURLOPT_URL,$url);
  
curl_setopt ($chCURLOPT_POST1);
 
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);       
 
curl_setopt($chCURLOPT_SSL_VERIFYHOST2);//setup post fields
 
curl_setopt ($chCURLOPT_POSTFIELDS,"Message=$message");
 
$ret curl_setopt($chCURLOPT_RETURNTRANSFER1);//If you are behind proxy then please uncomment below line and provide your proxy ip with port.
// $ret = curl_setopt($ch, CURLOPT_PROXY, "PROXY IP ADDRESS:PORT");

//execute and geting response
 
$curlresponse curl_exec($ch);

if(
curl_errno($ch))
    echo 
'curl error : 'curl_error($ch);

 if (empty(
$ret)) {
    
// some kind of an error happened
    
die(curl_error($ch));
    
curl_close($ch); // close cURL handler
 
} else {
    
$info curl_getinfo($ch);
    
curl_close($ch); // close cURL handler
    //echo "<br>";
    
echo $curlresponse;    //echo "post message Sent Succesfully" ;
    
}
 }

Email Script in PHP

Below script is simple email script in php. by using mail function


<?php 
// Email destination address
 $to 'to@email.com'; 
// Email Subject
 $subject 'PHP Simple Mailer Example'; 
// Email message 
$content 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
 Etiam sit amet elit vitae arcu interdum ullamcorper.'; 
// Additional headers

$headers  'MIME-Version: 1.0' "\n";
$headers .= 'Content-type: text; charset=iso-8859-1' "\n"; 
$headers .= 'From: from@email.com';

 mail($to,$subject,$content,$headers); 
?>