更多的Facebook php API设置 [英] More settings for the facebook php API
问题描述
也许我完全以错误的方式进行了搜索,而Facebook的文档对我来说是非常糟糕的。
Maybe I searched completely in the wrong way, and the facebook documentation pretty much sucks in my opinion.
我想知道,我通过以下设置连接到Facebook,并且可以检索登录用户的配置文件信息,允许我的应用程序访问他的个人资料。)还有其他可以设置的选项,如回调URL和到期(我想设置为从不,所以我可以将令牌保存在我的数据库中并重新使用)?
I was wondering, I'm connecting to facebook with the settings below and that works (I'm able to retrieve the profile information of the logged in user allows my application to access his profile.) Are there other options I can set, like the callback url and the expiration (which I want to set to never, so I can save the token in my db and re-use it)?
这是现在的配置:
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxx',
'cookie' => true
));
我也连接到twitter,我可以这样:
I'm also connection to twitter and there I'm able to this:
$this->configTwitter = array(
'callbackUrl' => 'xxxxxxxxxxxx',
'siteUrl' => 'http://twitter.com/oauth',
'consumerKey' => 'xxxxxxxxxxxx',
'consumerSecret' => 'xxxxxxxxxxxx'
);
提前感谢!
> Facebook应该看看Twitter
Facebook should take a look at Twitter
推荐答案
在尝试了几天之后,分发了图OAuth的文档2.0(它不能像预期的那样工作,搜索互联网我找到一个解决方案,我用来创建以下脚本:
After trying a few days, spitting the documentation of the Graph OAuth 2.0 (which doesn't work as good as expected and searching the internet I found a solution which I used to create the following script:
// Config
$this->redirectUrl = 'http://www.mywebsite.com/facebook'
$this->clientId = 'APPLICATION_ID';
$this->permissions = 'publish_stream,offline_access';
// Check if a sessions is present
if(!$_GET['session'])
{
// Authorize application
header('Location: http://www.facebook.com/connect/uiserver.php?app_id='.$this->clientId.'&next='.$this->redirectUrl.'&perms='.$this->permissions.'&return_session=1&session_version=3&fbconnect=0&canvas=1&legacy_return=1&method=permissions.request');
}
else
{
$token = json_decode($_GET['session']);
echo $token->access_token; // This is the access_token you'll need!
// Insert token in the database or whatever you want
}
这段代码工作得很好,并执行以下操作:
This piece of code works great and performs the following actions:
- 如果用户没有登录到Facebook
- 询问用户是否要添加应用程序,并在一个对话框中授予所请求的权限(在我的情况下为:publish_stream和offline_access)
- 返回到在redirectUrl下指定的一个access_token页面(因为我们要求离线访问这个页面不会过期)
然后我将令牌在数据库中,所以我不必再请求了。
I then store the token in the database so I won't have to request it again
现在你可以,如果你想使用Facebook代码,或者你是自己的代码来获取用户数据或Facebook的其他信息(请确保您请求正确的权限)
Now you can, if you wish use the facebook code, or you're own code to get the users data, or other information from facebook (be sure you requested the right permissions)
如果这是有效的代码,请不要现在,但它的效果非常好,我可以轻松定义'config'像我想要的。
Don't now if this is facebook-valid code, but it works great and I can easily define the 'config' like I wanted....
这篇关于更多的Facebook php API设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!