Get Facebook Access Token Using PHP SDK – Authentication
Get Facebook Access Token:
In this Post We Will Explain About is Get Facebook Access Token Using PHP SDK – Authentication With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to FacebookSession for the Facebook SDK for PHPExample
In this post we will show you Best way to implement How to handle access tokens with Facebook SDK, hear for Facebook API – Access Tokenswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
First of all simple steps get Facebook Access Token we need to simple use a Libs Like as a PHP SDK 5.4 or more to communicate with devloper account to Facebook API. we can download here PHP SDK 5.0 from following click to free link Download Facebook PHP API SDK 5.4 or more.The Facebook simple free SDK for PHP provides a all the server native interface to the as well as Graph API and easy way to Facebook Login.
What is an access token?
An access token is basically meaning of the really long ID as well as that is must required in order and api call to make calls to the facebook Graph API
User access token
A user access token looks like this:
CAsdwiWr8tH8BadminOIgoMwJ9T0ZAmJ6KJJNc5s5stdlive24u1s37D6us6eCEoy9r2VgrCLffCTvEGe9cZBZPAwBhygi2ZpTubZC2eCzfreStWG989898dXu4uJl2CCLiFXEtP4GKDv0Gk4s35iXty77KZBx5NYBCcEUsdownlJQcXLsb1X2ZsdfgsysDZN
System Requirements:
1. PHP 5.4 or greater 2. The simple Curl extension 3. The simple mbstring extension
getAccessToken.php
//include libs require_once __DIR__ . '/FacebookSDK/src/Facebook/autoload.php'; //pass arguments $facebook_args = array( 'consumer_key' => '19586578458256', 'consumer_secret' => 'bb3f2d58c73526b9aa0252a8813282f0', 'default_graph_version' => 'v2.2' ); $fbObj = new Facebook\Facebook($facebook_args); $fb_args_param = array('req_perms' => 'publish_actions'); $live_helper = $fbObj->getRedirectLoginHelper(); $fb_login_url = $live_helper->getLoginUrl('facebook_callback.php', $fb_args_param); header('Location: '. $fb_login_url); exit;
Now we need to allow some checkbox checked permission by click on Okay
facebook_callback.php
//include libs require_once __DIR__ . '/FacebookSDK/src/Facebook/autoload.php'; //pass arguments $facebook_args = array( 'consumer_key' => '19586578458256', 'consumer_secret' => 'bb3f2d58c73526b9aa0252a8813282f0', 'default_graph_version' => 'v2.2' ); $fbObj = new Facebook\Facebook($facebook_args); $live_helper = $fbObj->getRedirectLoginHelper(); try { // here facebook getAccessToken $get_accessToken = $live_helper->getAccessToken(); var_dump($get_accessToken); } catch(Facebook\Exceptions\FacebookResponseException $e) { //some message return echo 'we are fb Graph returned some an error: ' . $e->getMessage(); exit; } catch(Facebook\Exceptions\FacebookSDKException $e) { //some message return echo 'we are fb Facebook SDK returned some an error: ' . $e->getMessage(); exit; }
Now to extend the validity of this and get the access token use following source code after just mini to getting access token.
$colient_Auth2 = $fbObj->getOAuth2Client(); var_dump($colient_Auth2); $get_accessToken = $colient_Auth2->getLongLivedAccessToken($get_accessToken); var_dump($get_accessToken);
Now the simple steps to easy way access toke will be valid for next (3 months) 60 days.
I hope you have Got What is How To: Get A Facebook Application Access Token And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.