views:

211

answers:

1

Hello,

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/

A: 

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);

?>
pnm123