I’ve been working on this for a while now and I can’t seem to get it to work. It seems to be a frequently asked, but a rarely well-answered question.
I want my website’s users to link their facebook account with my website.
So they can see their stream e.t.c on my site.
At the moment, each time they log into my site they have to connect with facebook again.
I want to have the option for users to give me offline_access to their data, so they don’t have to re-login to facebook/re-connect with my site each time they come to my site. As its kind of the point of my site in general.
To do this I understand I need to get offline access. (https://developers.facebook.com/docs/authentication/) Though from my searching it seems to be a bit light on documentation ( Facebook offline access step-by-step ).
I already know how to ask for offline access I’m just unsure of how to get the data from it.
So my questions are as follows;
- How do I get the new infinate Session key after I request it?
- Once I have it and store it in the database – How do I create a facebook user with it instead of just going through the normal limited access key?
Just for further info. I’m using PHP (codeigniter) with Eliot Haughin’s Facebook connect library Though if you can give me code using the regular php library I’ll just convert it
Thanks very much
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
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.