PHP如何存储Facebook会话进一步使用 [英] PHP How can I store Facebook session for further uses

查看:177
本文介绍了PHP如何存储Facebook会话进一步使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Facebook整合到我的一个项目中。在这个时候我已经成功地整合了Twitter,所以用户可以在我们的网站上更新他们的状态。



有一次登录Twitter,然后我存储oauth_token ,oauth_token_secret,user_id和screen_name,所以当他们登录到我的网站(通过我自己的登录),他们不需要再次登录到Twitter。



现在,我想为Facebook做同样的事情。如何让用户将Facebook连接到我的网站并随时更新其状态,无需重新登录或其他。我的意思是,我需要存储什么,如何以及如何在更新状态时重新使用它?



我相信你已经理解了这个问题,希望我能得到我正在寻找的确切答案。



谢谢pnm123



PS:我使用以下SDK
http://github.com/facebook/php-sdk /

解决方案

我希望我刚刚找到答案。

 <?php 

require'facebook.php';

//创建我们的Application实例。
$ facebook = new Facebook(array(
'appId'=>'',
'secret'=>'',
'cookie'=> true,
));

//如果数据库包含用户的会话,请使用它。
$ 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);

?>


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/

解决方案

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

?>

这篇关于PHP如何存储Facebook会话进一步使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆