Here is the procedure that was used to write posts in facebook by allowing the user to signin using their facebook id and then writing a post in their facebook profile page.
1. use the following url with your own application id created in facebook
Then after the page is reloading, get the access token returned by facebook for the logged in user
3. use the following lines of code to get the facebook access token from the set cookie above and use it to send the post data via curl to facebook
Thats all..
1. use the following url with your own application id created in facebook
facebook login
Then after the page is reloading, get the access token returned by facebook for the logged in user
3. use the following lines of code to get the facebook access token from the set cookie above and use it to send the post data via curl to facebook
if(isset($_COOKIE['access_token_fb']))
{
/* NEVER DELETE THIS LINE. THIS IS THE MOST IMPORTANT LINE IN USING FACEBOOK */
json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' .$_COOKIE['access_token_fb']));
/* new testing code */
$url = "https://graph.facebook.com/me/feed";
$ch = curl_init();
$attachment = array( 'access_token' => $_COOKIE['access_token_fb'],
'name' => "Review for Product of #product#",
'link' => "www.thenewzealandweek.co.nz",
'description' => 'I have tried the product offered to me by thenewzealandweek.co.nz and here is the review I gave to that product.',
);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$result= curl_exec($ch);
curl_close ($ch);
/* new addition ends */
}
?>
Thats all..
Comments
Post a Comment