如何让 Facebook 应用程序安装/可安装/自动添加书签

发布于 2024-10-01 11:55:59 字数 1071 浏览 8 评论 0原文

我有这个 Facebook 应用程序配置文件页面:

http://www.facebook.com/developers/editapp.php?app_id=122313254494566#!/apps/application.php?id=122313254494566

与我的基于 iframe 的 Facebook 应用程序 Gem Spinner 相关联:

http://apps.facebook.com/gemspinner/

我通过阅读最近的 Facebook 文档了解到,过去几个月,Facebook 改变了用户为应用程序“添加书签”的方法(据我所知,“添加书签”是指将应用程序的图标添加到 Facebook 主页左侧的用户应用程序列表中的过程)页)。我的理解是,书签现在应该在人们第一次使用该应用程序时自动发生。

但我的应用程序并没有发生这种情况。当你去那里时,它只会向你显示应用程序页面并让你玩游戏。没有确认消息,就像我在其他应用程序中看到的那样,检查我是否允许该应用程序访问我的 Facebook 帐户中的各种信息。我的主页上的应用程序列表中没有添加书签/图标。

所以我显然错过了一些东西。我尝试按照此处的说明进行操作: http://developers.facebook.com/docs/guides/ canvas/,包括书签部分,但这部分再次听起来像是它会自动发生。

我的应用程序已被批准用于 Facebook 目录(尽管它尚未出现在目录搜索中)。而且它不是处于“沙盒”模式。

也许我必须调用一些 Facebook API 才能让用户“安装”该应用程序。如果是这样,我很想知道那些是什么。

I have this Facebook application profile page:

http://www.facebook.com/developers/editapp.php?app_id=122313254494566#!/apps/application.php?id=122313254494566

which is associated with my iframe-based Facebook application, Gem Spinner:

http://apps.facebook.com/gemspinner/

My understanding from reading recent Facebook documentation is that in the last couple months Facebook changed the method by which users can "bookmark" an app ("bookmarking" as I understand it, is the process of adding an icon for the application to the user's list of applications on the left side of the Facebook home page). My understanding is that bookmarking is now supposed to happen automatically the first time the person uses the app.

But that's not happening for my app. When you go there, it just shows you the app page and lets you play the game. There is no confirmation message, like I see with other apps, checking if I want to allow this app to access various information from my Facebook account. And there is no bookmark/icon added to the application list on my home page.

So I'm obviously missing something. I tried to follow the instructions here: http://developers.facebook.com/docs/guides/canvas/, including the part on bookmarks, but again that part makes it sound like it will just happen automatically.

My app has been approved for the Facebook directory (although it is not yet showing up in searches of the directory). And it's not in "sandbox" mode.

Perhaps there are some Facebook API calls I must make to let the user "install" the application. If so, I'd love to know what those are.

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

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

发布评论

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

评论(1

随遇而安 2024-10-08 11:55:59

显然,我缺少的是,有必要从 javascript 代码中调用 FB.login() ,以便让 facebook “自动”为用户的应用程序添加书签。我想这有一定的道理,因为在您的应用程序(或代表您的应用程序的 Facebook)可以对用户帐户进行任何更改(例如添加书签)之前,用户必须通过您的应用程序“进行身份验证”。尽管如此,似乎可能是在没有身份验证的情况下添加书签的情况,并且阅读 Facebook 文档的人肯定会认为,无论身份验证如何,只需访问该应用程序就会创建书签。

不管怎样,另一个问题是如何让认证顺利进行。可能有一种更聪明、更实用的方法可以使用页面重定向来完成此操作,但似乎这个新 API 想要为登录 UI 显示一个弹出窗口。如果该弹出窗口是通过按下按钮触发的(即,按钮表示/意味着“单击此处以通过此应用程序进行身份验证”),则您将获得弹出窗口,而不会出现可怕的浏览器弹出警告。但如果您自己调用 FB.login() 函数,您会收到可怕的警告。

因此,为了解决这个问题,我让代码触发了按钮事件,并且它有效(至少在 Firefox 上)。代码是:

  <body>
    <div id="fb-root">
    </div>
    <script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
    <script type="text/javascript">
      FB.init({
        appId  : 'your app id here',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : false  // parse XFBML
      });
      function fblogin() {
        FB.getLoginStatus(function(response) {
          if (response.session) {
            // logged in and connected user, someone you know
          } else {
            // no user session available, someone you dont know
            FB.login(
              function(response)
              {
                if (response.session)
                {
                  // user successfully logged in *or* user was already logged in
                  // *and* user has now been successfully authenticated for this app
                  // *and* a bookmark added by Facebook for this app
                }
                else
                {
                  // user cancelled login
                }
              } );
          }
        });
      }
    </script>
    <a id="clickme" href="#" onclick="fblogin();return false;"></a>

    ... the rest of your page here ...

    <script type="text/javascript">
      document.getElementById( "clickme" ).onclick();
    </script>
  </body>

这一切看起来都很黑客,但我不知道更好的方法来使身份验证自动发生,同时避免弹出警告。

在我看来, FB.login() 函数的命名很混乱。它的真正意思似乎是,“如果用户未登录,则显示登录 UI。但是,如果用户已经登录,或者用户使用 UI 成功登录,则还要对该应用程序的用户进行身份验证,包括自动验证为用户为此应用程序添加书签。”所以也许至少 loginAndAuthenticate() 会是一个更好的名字。

Apparently the thing I was missing is that it's necessary to call FB.login() from within your javascript code in order to get facebook to "automatically" bookmark the application for the user. I guess this makes a certain amount of sense, since the user has to be "authenticated" with your app before your app (or Facebook on behalf of your app) can make any changes to the user's account, such as adding a bookmark. Nonetheless, it seems like it could have been the case that it added the bookmark without the authentication, and certainly reading the Facebook documentation one would think that simply visiting the app would create the bookmark, regardless of the authentication.

Anyway, another problem was how to make the authentication happen in a smooth way. It may be that there's a more clever and more functional way to do this using page redirects, but it seems like this new API wants to show a pop-up window for the login UI. If that popup is triggered by a button press (i.e., a button that says/means "click here to authenticate with this application"), you get the popup without the terrible browser popup warning. But if you just call the FB.login() function yourself, you get the terrible warning.

So, to get around this, I had my code trigger the button event, and it worked (at least on Firefox). The code is:

  <body>
    <div id="fb-root">
    </div>
    <script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
    <script type="text/javascript">
      FB.init({
        appId  : 'your app id here',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : false  // parse XFBML
      });
      function fblogin() {
        FB.getLoginStatus(function(response) {
          if (response.session) {
            // logged in and connected user, someone you know
          } else {
            // no user session available, someone you dont know
            FB.login(
              function(response)
              {
                if (response.session)
                {
                  // user successfully logged in *or* user was already logged in
                  // *and* user has now been successfully authenticated for this app
                  // *and* a bookmark added by Facebook for this app
                }
                else
                {
                  // user cancelled login
                }
              } );
          }
        });
      }
    </script>
    <a id="clickme" href="#" onclick="fblogin();return false;"></a>

    ... the rest of your page here ...

    <script type="text/javascript">
      document.getElementById( "clickme" ).onclick();
    </script>
  </body>

This all seems pretty hackish, but I don't know a better way to make the authentication happen automatically while avoiding the popup warning.

It seems to me that the FB.login() function is confusingly named. It really seems to mean, "If the user is not logged in, present the login UI. But if the user is already logged in, or if the user successfully logs in using the UI, also authenticate the user for this application, including automatically bookmarking this application for the user." So maybe at least loginAndAuthenticate() would be a better name.

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