Hello every one. while working on a project for some client i have to post all new coupons added from admin side to his fan page on facebook (Automatically).

It took 1 week to complete this as there was a very small and tricky thing i was missing.

here is a very small and easy tutorial to post on fan page using php api of FaceBook.

Create Facebook Application and Download Facebook Api and include it into your code like this:

require_once(‘FacebookAPI/facebook.php’);

Provide Api Cardinalities: (You can get this when you will register your application)
$appapikey = ‘ed98b8a4bd1c7355eee0f7262f6cvvad8′;
$appsecret = ’8ebfa1d5aa8e9a663ebcdfc4db174c0vvee’;
$facebook = new Facebook($appapikey, $appsecret);
$fb = new FacebookRestClient($appapikey, $appsecret);

Provide Permanent Session Key : (i will write a tutorial to get permanent session key and user id some other time. for now you can google it):

//permanent session key is used to post on users behalf even you don’t have their password etc…

$facebook->api_client->session_key = $Permanent Session Key;
$userid=User id of user.;
$fetch = array(‘friends’ =>array(‘pattern’ => ‘.*’,'query’ => “select uid2 from friend where uid1={$userid}”));
$facebook->api_client->admin_setAppProperties(array(‘preload_fql’ => json_encode($fetch)));

That’s the Tricky part: you should have admin rights to post on fan page:

Enter API key and Fan page id in link. Fan page id is in url when you open a page.

http://www.facebook.com/connect/prompt_permissions.php?api_key=Your Api Key&v=1.0&next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display=page&ext_perm=publish_stream,offline_access&enable_profile_selector=1&profile_selector_ids=Your Fan Page ID

$page_id =”114014671970831″;
try
{
if( $facebook->api_client->stream_publish(“Thanks to Zeeveloper!”, null,null, null,$page_id))
echo “Added on FB Wall on Fan Page”;
}
catch(Exception $e)
{
echo $e . “<br />”;
}

That’s All

Enjoy ;)

  1. cxazbs says:

    VEqQ28 eqrcjptioabn, [url=http://xwirxrwcapsh.com/]xwirxrwcapsh[/url], [link=http://zcwqffqrmluj.com/]zcwqffqrmluj[/link], http://clhebyijioqy.com/

  2. 英文SEO says:

    Story, i enjoyed sharing this.