I'm trying to get friends list and I get this error:
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /server/url/base_facebook.php on line 970
This is the code I'm using:
$facebook = new Facebook(array(
'appId' => $appID,
'secret' => $appSecret,
开发者_JS百科 'cookie' => true, // enable optional cookie support
));
$result = $facebook->api('/me/friends/',array('access_token' => $facebook->access_token));
Here's the data I get back in the $facebook variable:
Facebook Object
(
[appId:protected] => 220........
[apiSecret:protected] => 2162e6c1b771......
[user:protected] =>
[signedRequest:protected] =>
[state:protected] => 894ad3b36c2ebdcbcf6d4f110641dd4f
[accessToken:protected] =>
[fileUploadSupport:protected] =>
)
For some reason the access_token is empty. It worked fine and suddenly stopped... The app already has the permissions and I'm using the latest PHP SDK v3.0.1
Please help me... I'm going crazy with this issue...
Thanks, Bar.
it seems like u need to parse the signed request first is this an iframe app or a website?
if it's an iframe app and the user already authorized
try this.
public function parse_signed_request($signed_request)
{
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$sig = $this->base64_url_decode($encoded_sig);
$data = json_decode($this->base64_url_decode($payload), true);
if(strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
throw new Exception('bad algorithm');
}
$expected_sig = hash_hmac('sha256', $payload, $this->app_secret, $raw = true);
if($sig !== $expected_sig) {
throw new Exception('Bad signed JSON');
}
return $data;
}
this will parse the signed request.
after u get the data var_dump it and in it u will see the oauth_token....
private function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
You should add $this->load->library('facebook');
in constructor .
You need to upgrade your SDK to v3.0:
https://github.com/facebook/php-sdk
Edit: Since you are using v.3.0 your construct is wrong.. there is no more $cookie parameter for constructor. I suggest revising documentation.
精彩评论