Take the 2-minute tour ×

Maybe I searched completely in the wrong way, and the facebook documentation pretty much sucks in my opinion.

I was wondering, I'm connecting to facebook with the settings below and that works (I'm able to retrieve the profile information of the logged in user allows my application to access his profile.) Are there other options I can set, like the callback url and the expiration (which I want to set to never, so I can save the token in my db and re-use it)?

This is the config now:

$facebook = new Facebook(array(
        'appId'  => 'xxxxxxxxxxxx',
        'secret' => 'xxxxxxxxxxxx',
        'cookie' => true

I'm also connection to twitter and there I'm able to this:

$this->configTwitter = array(
        'callbackUrl' => 'xxxxxxxxxxxx',
        'siteUrl' => 'http://twitter.com/oauth',
        'consumerKey' => 'xxxxxxxxxxxx',
        'consumerSecret' => 'xxxxxxxxxxxx'

Thanks in advance!

Facebook should take a look at Twitter

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

After trying a few days, spitting the documentation of the Graph OAuth 2.0 (which doesn't work as good as expected and searching the internet I found a solution which I used to create the following script:

    // Config
    $this->redirectUrl = 'http://www.mywebsite.com/facebook'
    $this->clientId = 'APPLICATION_ID';
    $this->permissions = 'publish_stream,offline_access';

    // Check if a sessions is present 
        // Authorize application
        header('Location: http://www.facebook.com/connect/uiserver.php?app_id='.$this->clientId.'&next='.$this->redirectUrl.'&perms='.$this->permissions.'&return_session=1&session_version=3&fbconnect=0&canvas=1&legacy_return=1&method=permissions.request');
        $token = json_decode($_GET['session']);
                    echo $token->access_token; // This is the access_token you'll need!

        // Insert token in the database or whatever you want

This piece of code works great and performs the following actions:

  1. Log in if the user isn't logged in to facebook
  2. Asks if the user wants to add the application and grants the requested permissions (in my case: publish_stream and offline_access) in one dialog
  3. returns to the page you specified under redirectUrl with an access_token (and because we requested for offline access this one doesn't expire)

I then store the token in the database so I won't have to request it again

Now you can, if you wish use the facebook code, or you're own code to get the users data, or other information from facebook (be sure you requested the right permissions)

Don't now if this is facebook-valid code, but it works great and I can easily define the 'config' like I wanted....

share|improve this answer
add comment

There are many settings you can set at the point of authenticating. Extended permissions let you set the offline_access so that you can authenticate and store your session in a db. More info on extended permissions are at developers.facebook.com/docs/authentication/permissions and you can read my blog post for more info on how to use them at http://www.joeyrivera.com/2010/facebook-graph-api-app-easy-w-php-sdk/

share|improve this answer
add comment

Your Answer


