获取持久的Facebook令牌

时间:2014-11-03 23:57:02

标签: facebook-graph-api facebook-php-sdk

通过Facebook的PHP SDK入门guide,它将引导您完成初始化应用程序,创建登录URL,然后处理回调数据和进行简单查询的过程。

在文档中,它说您可以跳过初始化过程,从“其他方式”提供访问令牌。

$session = new FacebookSession('access token here'); 

由于缺乏文档,我在如何在创建登录URL之前定义范围,然后使用回调数据提取访问令牌方面苦苦挣扎。

1 个答案:

答案 0 :(得分:1)

This tutorial将帮助您开始使用Facebook PHP SDK登录用户。

基本上,您需要先设置应用程序并使用FacebookRedirectLoginHelper创建登录URL:

FacebookSession::setDefaultApplication( 'xxx','yyy' );

// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'http://yourwebsite.com/app/' );

// show login url, scope is array of permissions
echo '<a href="' . $helper->getLoginUrl( [ 'email', 'user_friends' ] ) . '">Login</a>';