开发者

Storing facebook session data

I am using the Facebook PHP SDK and am storing the session when a user logs in...

if ($session = $facebook->getSession()) {
    mysql_query("UPDATE fb_session SET app_session = '" . addslashes(serialize($session)) . "' WHERE user_id = " . $uid);
}

I have a cron script running that uses the facebook API as the user via:

$facebook->setSession(unserialize($row['app_session']), false);

To set the script t开发者_运维技巧o the right user.

The problem is when a user logs out of facebook, the session is no longer valid and requires them to login again. I have a cron script so this screws it up as there is no user interaction.

Am I meant to be storing something different?


What are you trying to do?

If you just want to publish on behalf of the user then just ask for the publish_stream permission and store the user id in your DB.
After that you can publish without "getting a session" (i.e. without $facebook->setSession(...)).

And if you want to do other tasks, then aquire the offline_access permission and only store the access_token along with the user id in your DB, and perform your tasks also without setSession


Yes, you need to request the offline_access permission when your users connect with your application, which gives you permanent instead of temporary access tokens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜