facebook php API 的更多设置

发布于 2024-10-06 09:50:35 字数 710 浏览 0 评论 0原文

也许我搜索的方式完全错误,而且我认为 Facebook 文档非常糟糕。

我想知道,我正在使用下面的设置连接到 facebook 并且有效(我能够检索登录用户的个人资料信息,允许我的应用程序访问他的个人资料。)是否还有其他我可以设置的选项,例如回调 url 和过期时间(我想将其设置为从不,这样我就可以将令牌保存在我的数据库中并重新使用它)?

这是现在的配置:

$facebook = new Facebook(array(
        'appId'  => 'xxxxxxxxxxxx',
        'secret' => 'xxxxxxxxxxxx',
        'cookie' => true
    ));

我还连接到 Twitter,我可以这样做:

$this->configTwitter = array(
        'callbackUrl' => 'xxxxxxxxxxxx',
        'siteUrl' => 'http://twitter.com/oauth',
        'consumerKey' => 'xxxxxxxxxxxx',
        'consumerSecret' => 'xxxxxxxxxxxx'
    );

提前致谢!

Facebook 应该看看 Twitter

Maybe I searched completely in the wrong way, and the facebook documentation pretty much sucks in my opinion.

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

This is the config now:

$facebook = new Facebook(array(
        'appId'  => 'xxxxxxxxxxxx',
        'secret' => 'xxxxxxxxxxxx',
        'cookie' => true
    ));

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

Thanks in advance!

Facebook should take a look at Twitter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还给你自由 2024-10-13 09:50:35

经过几天的尝试,吐出 Graph OAuth 2.0 的文档(它的工作效果没有预期的那么好,并在互联网上搜索,我找到了一个解决方案,我用它来创建以下脚本:

    // 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
    }

这段代码工作得很好并且执行以下操作:

  1. 如果用户未登录 facebook,则登录
  2. 询问用户是否要添加应用程序并在一个对话框中授予请求的权限(在我的例子中:publish_stream 和offline_access)
  3. 返回到您在redirectUrl 下指定的页面一个access_token(因为我们请求离线访问,所以这个不会过期)

然后我将令牌存储在数据库中,这样我就不必再次请求它

现在你可以,如果你想使用facebook代码,或者你'重新编写自己的代码来获取用户数据或来自 facebook 的其他信息(确保您请求了正确的权限)

如果这是 facebook 有效的代码,现在不要这样做,但它工作得很好,我可以像我一样轻松定义“配置”通缉....

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:

  1. Log in if the user isn't logged in to facebook
  2. Asks if the user wants to add the application and grants the requested permissions (in my case: publish_stream and offline_access) in one dialog
  3. returns to the page you specified under redirectUrl with an access_token (and because we requested for offline access this one doesn't expire)

I then store the token in the database so I won't have to request it again

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)

Don't now if this is facebook-valid code, but it works great and I can easily define the 'config' like I wanted....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文