Reputation: 4974
Ever I send a token request to Facebook I receive a NULL
response. Not a exception or success response. Always NULL
$this->facebook = new Facebook(array(
'appId' => 'APP ID',
'secret' => 'APP SECRET',
'cookie' => true
));
if(isset($_GET['code'])) {
$token = $this->facebook->api('/oauth/access_token', 'GET', array(
'client_id' => 'APP ID',
'client_secret' => 'APP SECRET',
'redirect_uri' => 'http://mywebsite.com?route=' . urlencode('account/connect/facebook/'),
'code' => $_GET['code']
));
print_r($token); // NULL
exit;
} else {
$this->redirect($this->facebook->getLoginUrl(array(
'redirect_uri' => 'http://mywebsite.com?route=' . urlencode('account/connect/facebook/')
)
)
);
}
Upvotes: 2
Views: 565
Reputation: 96353
$token = $this->facebook->api('/oauth/access_token',
You can not use Facebook::api to makes this call, because that method expects a JSON response, which this endpoint does not respond with.
But why would you want to do this anyway? The PHP SDK already has the functionality to detect a passed code
parameter and exchange it for an access token included, and does it automatically.
Upvotes: 1
Reputation: 430
I think you can just do:
$token = $this->facebook->getAccessToken();
http://developers.facebook.com/docs/reference/php/facebook-getAccessToken/
Upvotes: 0