问题
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