When user access token , I am getting error like . Please help me immediately. How can I solve this,tell me
stdClass Object ( [error] => stdClass Object ( [message] => An active access token must be used to query information about the current user. [type] => OAuthException [code] => 2500 ) )
require 'facebook-php-sdk-v4/src/Facebook/autoload.php';
require("facebook.php");
$fb = new Facebook\Facebook([
'app_id' => '1501716620042981',
'app_secret' => '510d15193610ca682b7f79c156992bb5',
'default_graph_version' => 'v2.3',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
// Logged in!
echo $_SESSION['facebook_access_token'] = (string) $accessToken;
// Now you can redirect to another page and use the
// access token from $_SESSION['facebook_access_token']
}
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'https://graph.facebook.com/me/?fields=albums.fields(id,name,cover_photo,photos.fields(name,picture,source)),videos.type(uploaded)&'.$_SESSION['facebook_access_token']);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'fb');
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
$query = curl_exec($curl_handle);
curl_close($curl_handle);
print_r(json_decode($query));
You're not providing the access token in the right way. It should be presented as the value of the access_token
URL query parameter as in:
'https://graph.facebook.com/me/?fields=albums.fields(id,name,cover_photo,photos.fields(name,picture,source)),videos.type(uploaded)&access_token='.$_SESSION['facebook_access_token']
for clarity, without the specific fields:
'https://graph.facebook.com/me?access_token='.$_SESSION['facebook_access_token']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With