1 hour-
//before doing js sdk call initialize sdk at first written in
//this url-https://developers.facebook.com/docs/reference/javascript/
<script type="text/javascript">
FB.login(function(response) {
if (response.status=='connected') {
if (response.authResponse.accessToken) {
var token = response.authResponse.accessToken;
} else {
alert('You can create access token only for your profiles and pages.');
}
} else { alert('you have to create an access token.'); }
}, {scope:'user_groups,read_stream'});
</script>
To extend that token as long lived token(60 days) in server side code,
use the following exchange token url where $temptoken value will be the
short lived token generated above.Here i used curl call to call and get
result from the url -
$url="https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=app_id_here&client_secret=app_secret_code_here&fb_exchange_token=".$temptoken."";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$tmp = curl_exec($ch);
curl_close($ch);
echo $tmp; // $tmp contains the access token as well as other params.
Hope that helps.Don't forget to like & share the post.