简体   繁体   English

Facebook PHP SDK:“ iframe”页面标签上的用户ID

[英]Facebook PHP SDK: User ID on iframe page tab

I'm on my own page, I'm admin and I'm already "like" this peage, but this code: 我在自己的页面上,我是管理员,我已经“喜欢”这个豆豆,但是代码如下:

require_once "api/facebook.php";

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

$signedrequest = $facebook->getSignedRequest();
$uid = $facebook->getUser();

gives me just this data: 给我这些数据:

### USER ID ###

0

### SIGNED REQUEST ###

Array
(
    [algorithm] => HMAC-SHA256
    [issued_at] => 1330166798
    [page] => Array
        (
            [id] => 304887859549216
            [liked] => 1
            [admin] => 1
        )

    [user] => Array
        (
            [country] => us
            [locale] => en_US
            [age] => Array
                (
                    [min] => 21
                )
        )
)

So, getUser() = 0 and user id from signed request - empty. 因此,getUser()= 0,已签名请求中的用户ID为空。 What im doing wrong? 我在做什么错?

By default the "user" is the page, this way you can display content from your app relevant to the page. 默认情况下,“用户”是页面,通过这种方式,您可以显示应用程序中与页面相关的内容。 To determine who the user is, you can go through the standard backend redirects you would go through as if the user came to your app with no session/expired token. 要确定用户是谁,您可以进行标准的后端重定向,就像用户没有会话/过期令牌来到您的应用程序一样。 But you need to remember what page your were on since Facebook only passes that information on initial iframe load. 但您需要记住自己的页面,因为Facebook仅在初始iframe加载时传递该信息。

For a better user experience, I would use the Facebook javascript SDK. 为了获得更好的用户体验,我将使用Facebook javascript SDK。 You can check everything in javascript and determine who the user is without performing any redirects. 您可以检查javascript中的所有内容并确定用户是谁,而无需执行任何重定向。 You can even prompt for authorization without reloading the page. 您甚至可以提示授权而无需重新加载页面。 If the user already had authorized your app, they see no changes and get no prompts, but you now have a "session" with that user and know their ID in javascript. 如果用户已经授权了您的应用程序,则他们看不到任何更改,也没有任何提示,但是您现在与该用户进行了“会话”,并且在javascript中知道了其ID。

https://developers.facebook.com/docs/reference/javascript/FB.login/ https://developers.facebook.com/docs/reference/javascript/FB.login/

Just to add to this you can't currently get everything in the javascript SDK. 仅添加此内容,您当前无法在javascript SDK中获得所有内容。 It doesn't give you any of the user or page (for page tab) data which PHP SDK does. 它没有像PHP SDK那样为您提供任何用户或页面(页面选项卡)数据。

对于getUser,您需要登录您的应用程序,显示te login / permission对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM