如何在简单的 iframe 选项卡中提示用户访问用户 ID?

发布于 2025-01-08 18:30:05 字数 1209 浏览 0 评论 0原文

我知道这里有很多关于此的问答,但我似乎无法理解它们,因为它们没有显示完整的代码示例,或者用于做与我想做的不同的事情。

我有一个简单的 Facebook 欢迎测试选项卡。不是画布应用程序。我希望能够获取用户 ID,但必须提示他们访问该信息,然后才能将其显示在签名的请求中。

所以我正在寻找的是一个简单的欢迎选项卡的代码示例。我不需要登录页面或类似的内容,因为这将位于粉丝内容页面中,因此他们必须已经登录。我只是希望弹出该对话框,询问他们的许可,以便我可以获得用户 ID。

谢谢

编辑: 我想补充一点,我刚刚解决了我的问题,但这并不是这个问题的真正答案。我想出了如何在不询问用户访问其个人资料的权限的情况下获取用户 ID。只需将此代码添加到页面即可简单,并且它在选项卡和画布应用程序中的工作方式相同。 getUser() 本身返回 0,但由于用户已经登录才能查看此内容,因此当 getUser() 返回 0 时,代码只需从 API 方法获取用户 ID。现在我终于明白了这一点,这似乎很简单。

$session = $facebook->getUser();

if (!$session) {

    $url = $facebook->getLoginUrl(array(
        'canvas' => 1,
        'fbconnect' => 0
    ));

    echo "<script type='text/javascript'>top.location.href = '$url';</script>";

} else {

    try {

        $uid = $facebook->getUser();
        $me = $facebook->api('/me');

        $updated = date("l, F j, Y", strtotime($me['updated_time']));

        echo "Hello " . $me['name'] . "<br />";
        echo "You last updated your profile on " . $updated;

    } catch (FacebookApiException $e) {

        echo "Error:" . print_r($e, true);

    }
}

我仍然想知道是否有一种方法可以为选项卡应用程序显示扩展权限对话框,因此很高兴看到 php sdk 的解决方案。

I know there are many Q&A on here about this but I can't seem to make sense of them because they don't show full code examples or are for doing something different than what I'm trying to do.

I have a simple facebook welcome-test tab. Not a canvas app. I want to be able to get the users id but have to make it prompt them for access to that info before it will show up in the signed request.

So what I'm looking for is a code example for a simple welcome tab. I don't need a login page or anything like that since this will be in the fan content page so they will have to be logged in already. I just want that dialog box to popup asking them for permission so I can get the userid.

Thanks

Edit:
I wanted to add that I just figured out my problem but it's not really an answer to this question. I figured out how to get the user id without asking the user for permission to access their profile. It was as easy as adding this code to the page and it works in a tab and canvas app the same way. getUser() by its self returns 0 but since the user is already logged in to be seeing this content, when getUser() returns 0, then the code simply gets the user id from the API method. Now that I finally figured this out it seems simple.

$session = $facebook->getUser();

if (!$session) {

    $url = $facebook->getLoginUrl(array(
        'canvas' => 1,
        'fbconnect' => 0
    ));

    echo "<script type='text/javascript'>top.location.href = '$url';</script>";

} else {

    try {

        $uid = $facebook->getUser();
        $me = $facebook->api('/me');

        $updated = date("l, F j, Y", strtotime($me['updated_time']));

        echo "Hello " . $me['name'] . "<br />";
        echo "You last updated your profile on " . $updated;

    } catch (FacebookApiException $e) {

        echo "Error:" . print_r($e, true);

    }
}

I'd still like to know if there is a way to make the extended permissions dialog show for a tab app so it will be good to see solutions for php sdk.

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

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

发布评论

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

评论(2

岁月静好 2025-01-15 18:30:05

您需要提示他们允许您的应用程序提取用户数据,

这可以使用 JS SDK 的函数 FB.login() 来完成。您可以在 facebook 文档中了解更多详细信息:http://developers.facebook。 com/docs/reference/javascript/FB.login/

请注意,弹出窗口只能在 mouseclickkeyup 事件上打开 - 否则弹出窗口拦截器将阻止它。

您还必须在开发人员站点中为应用程序设置域和站点 URL,并初始化 facebook js 库(加载段落 - http://developers.facebook.com/docs/reference/javascript/)

<div onclick="login();">click here to login</div>

<script type="text/javascript">
function afterLogin(){
   alert("user logged");
}

function login(){
    FB.getLoginStatus(function(response){
        if(response.status=="connected")
        {
            afterLogin();
        } else {
            FB.login(function(response){
                if(response.status=="connected")
                {
                afterLogin();
                }
            });
        }
    });
}
</script>

you need to prompt them for allowing your application to pull data on the user

this can be done using the JS SDK's function FB.login(). you can have more details in the facebook documentation : http://developers.facebook.com/docs/reference/javascript/FB.login/

notice that the popup can be opened only on mouseclick or keyup events - otherwise popup blockers will block it.

you will also have to set a domain and site url to the application in the developers site, and init the facebook js library (the loading paragraph in - http://developers.facebook.com/docs/reference/javascript/)

<div onclick="login();">click here to login</div>

<script type="text/javascript">
function afterLogin(){
   alert("user logged");
}

function login(){
    FB.getLoginStatus(function(response){
        if(response.status=="connected")
        {
            afterLogin();
        } else {
            FB.login(function(response){
                if(response.status=="connected")
                {
                afterLogin();
                }
            });
        }
    });
}
</script>
日久见人心 2025-01-15 18:30:05

我不认为 Facebook 允许这样做...Facebook 不希望用户的选项卡能够检测到谁在查看它,并且可能向用户的朋友显示未向用户显示的信息。

我可能是错的:)

I don't think facebook allows this... Facebook does not want a user's tab to be able to detect who is looking at it, and possibly displaying information to a user's friends that isn't displayed to the user.

I can be wrong :)

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