开发者

how to make Facebook app install/installable/auto-bookmarked

开发者 https://www.devze.com 2023-01-24 06:03 出处:网络
I have this Facebook application profile page: http://www.facebook.com/developers/editapp.php?app_id=122313254494566#!/apps/application.php?id=122313254494566

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开发者_如何学Go'd love to know what those are.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消