Wednesday, February 27, 2013

Facebook Status Update Using Php Script

Facebook Status Update using Facebook Graph Api and Php Script.Its easy and very simple.But First You have Create Facebook Application because without any application ID this Task is not done.

Step for Facebook Update State :

1) Create Facebook class file :( Facebook_plugins_class.php ) 

in this add application id and language code and set facebook sdk on and then create one function
display_status_update() and apply its parameter.

function display_status_update($criteria=array()) {
        $app_id = $criteria['app_id'];
        $title = $criteria['title'];
        $message = $criteria['message'];
        $name = $criteria['name'];
        $link = $criteria['link'];
        $picture = $criteria['picture'];
        $caption = $criteria['caption'];
        $description = $criteria['description'];
       
        if($app_id=='') $app_id = $this->app_id;
        if($title=='') $title = '';
        if($message=='') $message = '';
        if($name=='') $name = '';
        if($link=='') $link = '';
        if($picture=='') $picture = '';
        if($caption=='') $caption = '';
        if($description=='') $description = '';
        $random = rand(9999,9999999).rand(9999,9999999).rand(9999,9999999);     
        $js ='
        <script>
        function fc_post_fb_update_'.$random.'() {
            FB.ui({
                method: \'feed\',
                message: \''.$message.'\',
                name: \''.$name.'\',
                 link: \''.$link.'\',
                 picture: \''.$picture.'\',
                 caption: \''.$caption.'\',
                 description: \''.$description.'\',
            });
        }
        </script>';
        $content = '<a href="javascript:" onclick="fc_post_fb_update_'.$random.'()">'.$title.'</a>';
        return $content.$js;
    }


1) Create Facebook Status Update file :(fb_update.php ) 
in this file include the above class and call this function.

<?php
include_once('Facebook_plugins_class.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php Web tutorials</title>
</head>
<body>
<h3>Facebook status update dialog</h3>
<div>
    <?php
    $f1 = new Facebook_plugins_class();
    $display = $f1->display_status_update(array('title'=>'Click here to update your Facebook status'));
    echo '1. Standard:<br>';
    echo '<b>'.$display.'</b>';
   
    echo '<br>';
   
    $display = $f1->display_status_update(array('title'=>'Click here to update your Facebook status', 'link'=>'http://tutjunction.com'));
    echo '2. Update status + share an attached link:<br>';
    echo '<b>'.$display.'</b>';
   
    echo '<br><br>';
   
    $display = $f1->display_status_update(array('title'=>'Click here to update your Facebook status', 'link'=>'http://tutjunction.com', 'description'=>'Have a look on the services offered by this company!', 'picture'=>'http://tutjunction.com/wp-content/upload/'));
    echo '3. Update status + share an attached link + description + custom picture attached:<br>';
    echo '<b>'.$display.'</b>';
   
    echo '<br><br>';
    echo '<b>Tip:</b><br>Our Facebook status function doesn\'t require your users to authorize your application before they can post to their wall. They can do it right away! Just try it yourself with one of the 3 examples above.';  ?>
</div>
</body>
</html>



No comments:

Post a Comment

Thanks....