Getting offline_access to work with Facebook

2020-02-08 18:28发布

I am using Facebooker with Rails to connect my application to Facebook. I can direct the user through the authorization process and through the process of granting offline access to my application.

How do I actually go about accessing the information offline? Is there a way to request a session_key that does not expire that I can use at a later point, so long as the user has not revoked the permissions for my application on Facebook?

Any help greatly appreciated. Advice need not be rails specific.

4条回答
▲ chillily
2楼-- · 2020-02-08 18:57

Once you ask for, and are granted, offline access the session key you get in the HTTP POST parameters from Facebook (fb_sig_session_key) will have no expiry.

You can check you have such a key by checking the fb_sig_expires parameter, if this is "0" then the session key has no expiry.

If you have an auth_token then you can call getSession to get the session key and check the expires field:

var auth = _auth.getSession(AuthToken);
string sessionKey = auth.session_key;
long uid = auth.uid;
bool expires = auth.expires > 0;
查看更多
forever°为你锁心
3楼-- · 2020-02-08 19:03

EDIT: apparently, granting "offline_access" still gives you (and will continue doing so) an infinite session key. just save this special key and use it in your call to Status.get etc. see here for a (PHP) code example.

http://wiki.developers.facebook.com/index.php/New_Design_User_Login :

many API calls no longer require session keys

so if your app is granted offline_access, you can use API calls listed here without a session_key.

And we're changing more methods so you won't need a session key to do something when the user is offline, like send a notification.

查看更多
放荡不羁爱自由
4楼-- · 2020-02-08 19:12

I just made a tutorial on my blog with a step by step explanation on how to access offline user's data. It assumes you're working with RoR and the Facebooker plugin.

查看更多
神经病院院长
5楼-- · 2020-02-08 19:18

Once you get offline access permission from a user, the trick is to call with a filter_key parameter of 'network'.

In PHP, it is:

$feed = $facebook->api_client->stream_get($uid, '', '', '', 20, 'network', '');

Try it, it works....

查看更多
登录 后发表回答