PHP How can I store Facebook session for further uses

穿精又带淫゛_ 提交于 2019-12-23 06:14:26

问题


I am trying to integrate Facebook to one of my projects. At this time I have successfully integrated Twitter so users can update their status while they are on my website.

There is a one-time login to Twitter and then I store oauth_token, oauth_token_secret, user_id and screen_name so when they login to my site (via my own login), they do not need to login to Twitter again.

And now, I want to do the same for Facebook. How can I let users connect Facebook to my site and update their status any time without re-login or other. I mean, what do I need to store and how and how do I need to re-use it when updating status?

I believe that you have understood the question and I hope that I will get the exact answer that I am looking for.

Thank you, pnm123

PS: I am using the following SDK http://github.com/facebook/php-sdk/


回答1:


I hope that I have just found the answer.

<?php

require 'facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => '',
  'secret' => '',
  'cookie' => true,
));

//If the database contains user's session, use it.
$session = array(
    'uid' => '',
    'session_key' => '',
    'secret' => '',
    'access_token' => ''
);
ksort($session);
$sessionStr = '';
foreach($session as $sessionKey => $sessionValue) $sessionStr .= implode('=', array($sessionKey, $sessionValue));
$session['sig'] = md5($sessionStr.'App Secret');
$facebook->setSession($session, false);

?>


来源:https://stackoverflow.com/questions/3001403/php-how-can-i-store-facebook-session-for-further-uses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!