3
votes

I'm using Facebook Connect on a website.
I login the user. I ask for publish_stream, user_about_me among other permissions

Using JS SDK FB.login function, I check response.authResponse object and then post through jQuery Ajax the following data to a separate php file for processing:

  • response.authResponse.accessToken
  • response.authResponse.userID

The process.php file gets these parameters through $_POST and saves uid, token, name, etc. into a database.

https://graph.facebook.com/$uid?access_token=$token

Then in same file I try to exchange his user token for an extended one

https://graph.facebook.com/oauth/access_token?client_id=$appid&client_secret=$appsecret&grant_type=fb_exchange_token&fb_exchange_token=$token

I don't know what's wrong but I get the following

code 190

Is there any way to solve this?

Thanks

2
debug your access token here before extending it, to know if it's valid or not. - ThePCWizard
@ThePCWizard I've already debugged it, and I've got that is valid, but the ajax call to the process.php file is still being marked as red in Firebug (due to above error) - Enrique
the tokens are short lived and expire after 1-2 hours, have you tried purging database, cache, etc. or with a facebook account you know you have not used before? - Ekim
@Ekim yes I use always a separate account to test the apps - Enrique

2 Answers

0
votes

If your $token is verified to be valid, then your $appid or $appsecret variables must be set incorrectly.

Print out the whole string and verify the appId and appSecret are what they should be.

Be aware that if you "manually" log out of facebook before the access token is exchanged, the (short-lived) token will be invalidated and the token exchange will fail.

0
votes

An easy solution might be the usage of the PHP SDK in the php file:

https://github.com/facebook/facebook-php-sdk

I guess you are using AJAX to call the php file, so you might need to set the Access Token with the "setAccessToken" function of the PHP SDK. After that, use "setExtendedAccessToken", no need to do all that stuff on your own and the PHP SDK is official.