When a developer start using Facebook Graph API first thing that comes to his mind is authentication by Facebook. Most popular word used is Facebook documentation for this is access token.
What is access token?
Why i need it?
What is its purpose?
These are the common question comes to developers mind when he/she heard about this world.
Facebook implementation of the OAuth 2.0 involves three different steps:-1. User authentication, 2. App authorization and 3. App authentication. User authentication ensures that the user is who they say they are. App authorization ensures that the user knows exactly what data and capabilities they are providing to your app. App authentication ensures that the user is giving their information to your app and not someone else. Once these steps are complete, your app is issued an user access token that you enables you to access the user's information and take actions on their behalf.
How to get access token by PHP SDK ?
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
));
$facebook->getAccessToken();
How to get extend it ?
PHP sdk 3.2.2 provides inbuilt method to extend access token to 60 days validity. The function name is setExtendedAccessToken, and it destroys the session afterwards, to remove the risk of having two active sessions.
Also, the function no longer actually returns the token, but instead stores it within the persistant data. You can therefore get the new access token with the public function getAccessToken afterwards.
Grab the new SDK from official Facebook PHP SDK github page to make sure you're up to date.
$facebook->setExtendedAccessToken();
$facebook->getAccessToken();
Access token Debugging
Debug online
https://developers.facebook.com/tools/debug
Debug by api
GET /debug_token?
input_token={input-token}&
access_token={access-token}
https://developers.facebook.com/docs/facebook-login/access-tokens/#debug
How to handle expired tokens
Official documentation have some good resources to explain this.
https://developers.facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/
More about tokens
https://developers.facebook.com/docs/facebook-login/access-tokens/
By:
Unknown
On 4:48 AM