Facebook API:FB.Connect.requireSession问题 [英] Facebook API: FB.Connect.requireSession issues

查看:75
本文介绍了Facebook API:FB.Connect.requireSession问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个构建为iFrame的 Facebook应用程序。我正在使用通过以下方式加载的JavaScript客户端API:

I have a Facebook app that is built as an iFrame. I am using the JavaScript client API loaded via:

  • http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php

在我的初始化代码中,我使用 requireLogin 确保用户已授权该应用程序。我发现这是必要的,以便能够收集记分牌的用户名,头像等。这是一个代表性的代码片段:

In my initialization code, I use the requireLogin method to ensure that the user has authorized the app. I have found this to be necessary to be able to gather the user's name, avatar, etc. for the scoreboard. Here's a representative code snippet:

FB_RequireFeatures(["Connect","Api"], function() {

    FB.Facebook.init("...API_KEY_HERE...", "xd_receiver.htm");

    var api = FB.Facebook.apiClient;
    api.requireLogin(function() {
        api.users_getInfo(
            FB.Connect.get_loggedInUser(),
            ["name", "pic_square", "profile_url"],
            function(users, ex) {
                /* use the data here */
            });
    });
});

这导致iframe重定向,导致Facebook授权屏幕在我的应用程序的iFrame中加载。这看起来很简单,并且对用户有些混乱。有两个Facebook酒吧等。

This causes the iframe to redirect causing the Facebook authorization screen to load within my app's iFrame. This looks junky and is somewhat confusing to the user, e.g. there are two Facebook bars, etc.

问题1:有什么我可以做的清理这个,而仍然实现为iFrame,并仍然使用JavaScript API?

Question 1: is there anything I can do to clean this up while still implementing as an iFrame, and still using the JavaScript APIs?

根据 FB API文档


FB.ApiClient.requireLogin

此方法已弃用 - 使用
FB.Connect.requireSession

This method is deprecated - use FB.Connect.requireSession instead.

当我用 FB.Connect.requireSession 替换 api.requireLogin 时,我的经验,它从未被调用。我更喜欢这样做的推荐方式,但我努力奋斗,无法找到一种方法来使其工作。我尝试为其他两个参数添加各种参数,似乎没有任何效果。我的期望是这个方法将加载到我的应用程序iFrame中的一个对话框中,具有类似的授权消息。

My experience though when I replace api.requireLogin with FB.Connect.requireSession it never gets invoked. I'd prefer the recommended way of doing it but I struggled and was not able to find a way to get it to work. I tried adding various arguments for the other two parameters as well with seemingly no effect. My expectation is that this method will load in a dialog box inside my app iFrame with a similar authorization message.

问题2:缺少获取 FB.Connect.requireSession 以正确提示用户授权?

Question 2: what am I missing with getting FB.Connect.requireSession to properly prompt the user for authorization?

最后,在该游戏,该应用程序提示用户通过 FB.Connect.streamPublish 将他们的分数发布到他们的流。这导致我...

Finally, at the end of the game, the app prompts the user for the ability to publish their score to their stream via FB.Connect.streamPublish. Which leads me to...

问题3:我正在加载正确的功能?我需要Api和Connect吗?我错过任何其他人吗?

Question 3: am I loading the correct features? Do I need both "Api" and "Connect"? Am I missing any others?

推荐答案

我认为FB.requireSession仅在
之外的FB连接网站Facebook的。如果您正在使用apps.facebook.com上托管的应用程序,请使用php api
调用,

I think that FB.requireSession only works from a FB connect site outside of Facebook. If you're using an app hosted on apps.facebook.com use the php api call instead,

$ facebook = new Facebook($ appapikey,$ appsecret);
$ facebook-> require_login();

$facebook = new Facebook($appapikey, $appsecret); $facebook->require_login();

或链接到登录页面。

这些登录方法

*  Using the PHP client library
* Directing users to login.php
* Including the requirelogin attribute in a link or form
* Using FBML 

只有前2个可用于在apps.facebook.com上托管的iframe应用程序

only the first 2 are available to iframe apps hosted on apps.facebook.com

我认为requirelogin和fbml仅适用于fbml canvas应用程序。

I think requirelogin and fbml only work with fbml canvas apps.

请参阅
http://wiki.developers.facebook.com/ index.php / Authorization_and_Authentication_for_Canvas_Page_Applications_on_Facebook

这篇关于Facebook API:FB.Connect.requireSession问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆