I am Using following to get appToken
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/oauth/access_token?client_id='.$config->getAppId().'&client_secret='.$config->getAppSecret().'&grant_type=client_credentials&scope=offline_access');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$app_token= curl_exec($ch);
curl_close($ch);
and uses graph api to get details from request id using following snippet
$ch = curl_init();
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$requestId.'?'.$app_token);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$request= curl_exec($ch);
curl_close($ch);
Everything works fine except in IE...
when using my app in IE i got following error in log
PHP Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user.
thrown in facebook.php on line 560,
referer: http://< my_url >?request_ids=1934696176864&ref=notif¬if_t=app_request
EDIT - Complete Code
<?php
include './facebook.php';
include './config.php';
include './database.php';
$config = new Config();
$database = new Database();
$facebook = new Facebook(array(
'appId' => $config->getAppId(),
'secret' => $config->getAppSecret(),
'cookie' => false,
));
$sent_to_id='';
if(isset($_GET['request_ids']) && !empty($_GET['request_ids'])){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/oauth/access_token?client_id='.$config->getAppId().'&client_secret='.$config->getAppSecret().'&grant_type=client_credentials&scope=offline_access');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$app_token= curl_exec($ch);
curl_close($ch);
echo 'Acces_Token: '.$app_token .", Session Acces Token: ".$session['access_token'];
//$app_token = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.$config->getAppId().'&client_secret='.$config->getAppSecret().'&grant_type=client_credentials'); //Get application token
$sent = explode(',', $_GET['request_ids']); //Convert csv to array
$count = count($sent); //count how many objects in array
for ($a = 0; $a < $count; $a++) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$sent[$a].'?'.$app_token);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$request= curl_exec($ch);
curl_close($ch);
//$request = file_get_contents('https://graph.facebook.com/'.$sent[$a].'?'.$app_token);
preg_match("/\"to\":\{\"name\":\"(.*?)\",\"id\":\"(.*?)\"/i", $request, $getInfo);
echo "sent[.".$a."] : ". $sent[$a] .", getInfo[1]: " . $getInfo[1] . ", getInfo[2]: ". $getInfo[2] ;
echo ", AppToken: ".$app_token;
$sent_to_name_temp= $getInfo[1];
$sent_to_id_temp = $getInfo[2];
if(!empty($sent_to_name_temp) && !empty($sent_to_id_temp)){
$sent_to_id .= $getInfo[2] . ',';
}
}
}
$sent_to_id = substr($sent_to_id, 0 , strlen($sent_to_id));
$userIds = explode(',', $sent_to_id);
$database->insert_invites($_GET['id'],$_GET['request_ids'], $userIds);
?>
Client Side code
function showInvite(invitedby) {
FB.ui({
method: "apprequests",
message: "Hey this is just for a testing App!",
data: "accepted", //This will be passed back to you when a user accepts the request
title: "Title wil be here!"
},
function(response) {
if (response && response.request_ids) {
ajaxRequest(invitedby, response.request_ids);
$(".message").html("Your invitation has been sent");
} else {
//alert('You must select some friends to send invitation!');
}
});
}
function ajaxRequest(invitedby, requestIds){
$.ajax({
url:"insertInvites.php?id=" + invitedby +"&request_ids="+requestIds,
success:function(){
//alert("Successfully inserted into table");
},
failure:function(){
//alert("Error while insertting into database");
}
});
}
Your PHP is running on the server, not in the browser. You need to check the input you're getting from the one particular browser (IE) and figure out what is wrong.
$session = $facebook->getSession();
$session['access_token'];
have a look @ Authenticating a FACEBOOK Application - PHP
I had a similar problem with IE9 and my canvas app because IE9 by default rejects 3rd party cookies without a proper compact privacy policy.
This fixed my IE specific problem.)
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');