Facebook offline access step-by-step

Viewed 61121

UPDATE: Facebook offline_access permission is being deprecated. Please refer to the official documentation for more information.
You'll have till May 1, 2012, at which date this setting will be disabled. refer to the Developer Roadmap for more info.


After searching literally 1 day on facebook and google for an up-to-date and working way to do something seemingly simple:

I am looking for a step-by-step explanation to get offline_access for a user for a facebook app and then using this (session key) to retrieve offline & not within a browser friends & profile data.

Preferrably doing this in the Fb Java API.

Thanks.

And yes I did check the facebook wiki.

Update: Anyone?

this: http://www.facebook.com/authorize.php?api_key=<api-key>&v=1.0&ext_perm=offline_access gives me offline_Access, however how to retrieve the session_key?

Why can't facebook just do simple documentation, I mean there are like 600 people working there?

The seemingly same question: Getting offline_access to work with Facebook Does not answer how to retrieve the session key

Edit: I am still stuck with that. I guess nobody really tried such a batch access out yet...

7 Answers

For session access, i had to use the loginurl provided by the facebook php api, as there seem to be 2/3 additional variables that it sends in the auth request, including return_session and session_version. Also the new php5-sdk sends the request to login.facebook.com instead of https://graph.facebook.com/oauth/authorize. Here's how i worked it out :

$b=new facebook(array('appId'=>APP_ID,'secret'=>SECRET))

To ask for authentication :

$facebook->getLoginUrl(array('next'=>$redirect_uri,'req_perms'=>$scope))

Rember to include offline_access in $scope. Once you are redirected to this page (after logging in to fb, and granting permissions), you will have a $_GET['session'] in json format.

Just store it wherever you want (I do it in a database). The next time you wish to do something with the user's account, just use the following:

$session = json_decode($db->query("SELECT ..."));//get session from db $this->facebook->setSession($session);

After this any requests that the api makes will be via this user's access.

The worst thing about the current facebook graph api is (correct me if I'm wrong) that the current api neglects the session (which seems to be a remain from the old api) in all its documentation and only talks about the access_token. But the current api (php5-sdk) has got no feature to send an actual request using only the access_token. If there is a function to start a session a session using only the access_token, I'm not aware of it.

Related