通过推荐进行 Facebook canvas 身份验证

发布于 2024-12-27 08:11:49 字数 1028 浏览 1 评论 0原文

我已经被这个问题困扰了一段时间了,今天我放弃了,我意识到我真的非常需要帮助,而且我找不到任何解决类似问题的帖子..所以

我正在尝试创建一个Facebook应用程序(自 2012 年 1 月 1 日起 - 如果有任何标准更改,你们可以告诉我),并且我已经正确设置了我的画布 url。

因此,现在当您在 Facebook 上访问我的应用程序(apps.facebook.com/canvas-page)时,您可以看到我的应用程序。但是我在身份验证方面遇到问题。

我的应用程序需要基本信息以及尝试访问它的用户的电子邮件地址。

据我所知,我已经设置了它,以便新用户可以看到身份验证对话框,然后访问我的应用程序。在访问我的应用程序时,我希望我的应用程序能够访问我上面所述的信息。然而,在我的画布页面上,我对 php 中的代码执行了以下操作,没有执行其他操作,我希望能够查看身份验证对话框中的 facebook 推荐将哪些信息传递到我的应用程序:

    <?php 
    print_r($_GET);
    echo "\n";
    print_r($_POST);
    ?>

然而遗憾的是,这给了我空数组,没有别的。

我的 Facebook 应用程序真正需要的是 access_token 和用户 id,尽管我很确定我可以通过访问 graph.facebook.com/me?access_token=[从某处提供的访问令牌] 来访问当前用户的 id,

所以这就是我的第一个问题,第二个问题是,当我注销 facebook 并访问 apps.facebook.com/canvas-page 时,我没有被要求登录,为什么会这样?我是否必须使用 JavaScript 重定向到 Facebook 才能登录,然后引用我的应用程序?

目前这些是我的设置(询问更多信息,以便我可以将它们提供给您) 设置>验证对话框>经过身份验证的推荐>用户&好友权限 = 电子邮件 设置>验证对话框>经过身份验证的推荐> Auth Token 参数 = ?code=

设置 >高级>迁移=全部启用

I have been stuck with this problem for a while now, and I just gave up today, I realized I really badly need help, and i couldn't find any posts addressing a similar issue.. so

I am trying to create a facebook app (since jan 1 2012 - incase there has been any standards change, you guys can tell me about it), and I have properly set my canvas url.

So right now when you visit my app on facebook, as apps.facebook.com/canvas-page you can see my app. However I am having problem with authentication.

My app requires basic information, and email address of the user trying to access it.

So as far as I have gotten so far, I have set it so that new users can see the authentication dialog and then visit my app. On visiting my app I want my app to be able to access the information as I stated above. However on my canvas page I did the following for code in php, and nothing else, I want to be able to see what information is passed on to my app by the facebook referral from the authentication dialog:

    <?php 
    print_r($_GET);
    echo "\n";
    print_r($_POST);
    ?>

However sadly this is giving me empty arrays, and nothing else.

All I really need for my Facebook app is the access_token, and the user id, although I am pretty sure I can access the current user's id by visiting graph.facebook.com/me?access_token=[access token provided from somewhere]

so thats my first problem, second problem is that when I logout of facebook and I visit apps.facebook.com/canvas-page I don't get asked to login, why is that so? Do I have to redirect to Facebook using JavaScript to login and then refer to my app?

Currently these are my settings (ask for more info so that i can give them to you)
Settings > Auth Dialog > Authenticated referrals > User & Friend permission = email
Settings > Auth Dialog > Authenticated referrals > Auth Token parameter = ?code=

Settings > Advanced > migrations = ALL ENABLED

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

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

发布评论

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

评论(1

讽刺将军 2025-01-03 08:11:49

FB 使用签名请求将数据发送到您的应用(不是 $_POST,不是 $_GET )。 Sample Canvas App 中有一个名为 signed_request Parameter 的章节那说说吧。

使用 php-sdk 你可以像这样获取它:

$signed_request = $facebook->getSignedRequest();

var_dump($signed_request);

array (
  'algorithm' => 'HMAC-SHA256',
  'expires' => 1326632400,
  'issued_at' => 1326628636,
  'oauth_token' => '***',
  'page' => 
  array (
    'id' => '***',
    'liked' => false,
    'admin' => true,
  ),
  'user' => 
  array (
    'country' => 'cl',
    'locale' => 'en_US',
    'age' => 
    array (
      'min' => 21,
    ),
  ),
  'user_id' => '***',
)

此外你可以传递一个名为app_data 通过 URL:

"http://www.facebook.com/YourPage?v=app_1234567890&app_data=any_string_here"

您也会在 $signed_request 中获取它。

...
array (
  'algorithm' => 'HMAC-SHA256',
  'app_data' => 'any_string_here',
  'expires' => 1326636000,
  'issued_at' => 1326629411,
...

请评论!谢谢。-

FB use Signed Request to send data to your app (not $_POST, not $_GET). There is a chapter called signed_request Parameter in Sample Canvas App that talk about it.

Using php-sdk you can obtain it like this:

$signed_request = $facebook->getSignedRequest();

var_dump($signed_request);

array (
  'algorithm' => 'HMAC-SHA256',
  'expires' => 1326632400,
  'issued_at' => 1326628636,
  'oauth_token' => '***',
  'page' => 
  array (
    'id' => '***',
    'liked' => false,
    'admin' => true,
  ),
  'user' => 
  array (
    'country' => 'cl',
    'locale' => 'en_US',
    'age' => 
    array (
      'min' => 21,
    ),
  ),
  'user_id' => '***',
)

Besides you can pass a parameter called app_data through URL:

"http://www.facebook.com/YourPage?v=app_1234567890&app_data=any_string_here"

You will get it in the $signed_request too.

...
array (
  'algorithm' => 'HMAC-SHA256',
  'app_data' => 'any_string_here',
  'expires' => 1326636000,
  'issued_at' => 1326629411,
...

Please comment! Thanks.-

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