I am using client side sdk for Login and in server side php sdk for 'wall posting' on a triggered action using graph api ( I was using it with offline_access but now I know its deprecated ).
How to get Extended access token in Server-side using client side sdk so that I can use the extended token in server side,
I know some answers are there like here, but they use Server-side login and get extended token from $_REQUEST['code'] which they get in response,
I there any way that I can get the value of $_REQUEST['code'] using client side login?
Update:
My client login code supports oAuth:
FB.init({
appId : 'MYAPPID', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true // enable OAuth 2.0
});
FB.login(function() {
FB.api('/me', {'fields': "some coma seperated fields"},
function(response){
//Function that sends data to server
Pass_data_to_server( response );
});
}, scope:'some scope values');
Server side code:
<?php
$settings = array
(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true,
'oauth' => true
);
// Get facebook object from facebook sdk class
$facebook = new Facebook($settings);
if ($facebook)
{
$user_id = $facebook->getUser();
$facebook->setExtendedAccessToken(); //long-live access_token 60 days
$token = $facebook->getAccessToken();
try
{
$response = $facebook->api('me/og.like', 'POST',{ $MYCUSTOMDATA});
return $response;
}
catch (FacebookApiException $e)
{
print_r($e)
return false;
}
}
?>