Facebook Offline Access Step-By-Step

Facebook Offline Access Key and login

Right. After some more searching and poking around the code. I figured it out.

I've tested it out for multiple users and over the course of a week and it works like a charm.

When you have gotten the offline_access permission, store the session key, and the user ID. (wherever you want. I store mine in my database).

The infinite session key will look something like this df4175330aaddb9d50fd8f84-30000799
with everything after the 'dash' being the users ID.

Then the next time you call the API add this line of code in.

$this->fb->set_user('Facebook User ID', 'Offline Access Session key', 0);
N.B. the zero is the amount of time before it will expire. 0 = never.

My code in my library is as follows

$this->fb = new Facebook($this->_api_key, $this->_secret_key);     
//Query Database to see if user had enabled offline access.
//If So extract the userid and session key
$this->fb->set_user($fbuserid, $fbsess, 0);

In my testing this has worked perfectly.
Now my users can log into my site and have facebook automatically, once they give the offline_access permission. Its currently been working for a week without problems.

I think thats everything. But if I left anything out let me know.

Facebook App: Where do i put offline_access request?

It's used with the API, as follows

$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => false,
));

$facebook_login_url = $facebook->getLoginUrl(array(
'next' => '',
'cancel_url' => '',
'req_perms' => 'email,publish_stream,status_update'
));

Where $facebook_login_url is the URL tha the user needs to follow to grant you access.

Does that help?



Related Topics



Leave a reply



Submit