Snipe.Net - Geeky Stuff
Twitter
Currently: @etamotweet Don't get me started. in reply to etamotweet 2 hrs ago

%$#^%$* Facebook Application Tabs

So this is new. And by new I mean painfully similar to the types of major functionality bugs we see every time there is a large-scale functionality change in Facebook.

I don’t know if this is a bug, or just undocumented, but I am unable to get the FBID of a user (even one who has allowed and interacted with the app) if the application is on its own tab in a fan page. I can get it on the boxes tab (by way of a workaround below) or on its own canvas page, but nothing works for the application tab.

Part of one of the recent changes to the platform was that you could no longer use require_login() from a tab (boxes or application). You can still use it on the application’s canvas page, but when you try to use require_login() in a tab, you’ll get an error that tells you you cannot redirect, something like:

fb:redirect: redirect forbidden by flavor TabFBMLFlavor

A suggestion on the developer forums suggests using:

$is_tab = isset($_POST['fb_sig_in_profile_tab']);
if( !$is_tab ) $user = $fb->require_login();

This basically checks to see if the application is being accessed via a tab (versus the canvas page or profile box). If it is being accessed via a tab, use the $_POST['fb_sig_in_profile_tab'], and if not, go ahead with require_login() as usual.

The problem is, while this works on profile tabs, it does NOT work on fan page tabs. When you use $_POST['fb_sig_in_profile_tab'] in an application on a fan page tab (or any of the other non-require_login() methods of getting a user’s ID) you end up with the ID of the fan page, NOT the viewing user.

This is a major problem for me, as many of the applications I have to build are not meant for addition to the directory, but are instead meant to be used only on a corporation’s fan page. The inability to access the user’s FBID severely limits what that application can do. In fact, it more often than not renders it completely useless.

To work around this, you can use the following to get the FBID of a user when your application is appearing in the Boxes tab:

function get_user() {
global $facebook;
global $authorized;
$authorized=true;

// this will fail if user hasn't authorized:
try { return $facebook->api_client->users_getLoggedInUser(); }

$authorized=false;
return $facebook->get_canvas_user()
}

and then setting the $user FBID variable with:

$user = get_user();

However, even this does not work on applications appear in their own tab on a fan page.

I downloaded Facebook’s sample application, “Smiley”, to attempt to see how they did it. I’m certainly not new to Facebook application development, but I figured using their own code would help me see how they handle this particular issue.

I, of course, made the gross assumption that their own sample application would be updated with the most recent API calls and best practices. Not only is the Smiley’s app not up to date with the most recent ApI changes, it is flat-out *broken*. Thanks to several files that are completely *missing*, Smiley’s doesn’t even run. The very first line of the index.php makes an include call to a file called constants.php that DOES NOT EXIST. Well done, as usual, Facebook. The new API changes have been out for weeks now – there is just no excuse foer the ongoing broken samples and stubbed or missing documentation.

I have spoken to Facebook and they insist that this was a policy decision to prevent applications from spamming users – however there are a few problems with this explanation:

  1. The FB user’s decide what applications can message them, email them, etc – and by blocking an app, they never hear from them again anyway. Application behavior is irrelevant.
  2. If they were concerned with spamming, why does this behavior only emerge when the app is on its own tab? Its okay to spam from Boxes and canvas then?
  3. If the user has allowed the application, they have voluntarily given the app their information.
  4. Disallowing applications from accessing the FBID of users who have allowed the application renders many applications completely useless. They’re basically statis HTML pages, and it seems unlikely that Facebook would so detrimentally cripple such an important part of the platform.

I suspect that I’m receiving inaccurate information from Facebook regarding this behavior, and I suspect this may be a bug. If this behavior was actually implemented to prevent applications from getting the FBID of users who have allowed it, the decision would have applied to Boxes as well.

I’m still going back and forth with Facebook on this, but I wanted to post it here in case other Facebook application developers are having the same trouble. When I discover the fix, I’ll post a followup here.

Also check out:

If you think this article kicked ass, subscribe to the RSS feed or follow me on Twitter! Share with your friends, or leave a comment below (or better still, do both!) My entire concept of self-worth is in your hands, so that makes you kind of a big deal. Srsly.

This entry was posted on Thursday, April 30th, 2009 at 3:28 pm and is filed under Web Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

View Comments to “%$#^%$* Facebook Application Tabs”

  1. Jun 22nd

    You don't need multiple users to publish an app, only to list it in the directory. Please see my response to Manjula.

  2. Mrunali
    Jun 22nd

    My application is not in Sandbox mode, but none of my friends are able to view this application. How can they use this application if it is not available in active directory?

  3. Jun 22nd

    You can send them a link to it.
    What's the app url?

  4. Manjula
    Jun 22nd

    Snipe – Can you help me in adding a button on a facebook application tab that posts back to itself? Thx

  5. Mrunali
    Jun 22nd

    My application URL is – http://www.facebook.com/mrunali.sing
    This is application tab.

    Can you also reply to Manjula's question about the button postback in the page. I have the same issue here. My button postbacks to itself but the tabs go missing.

  6. Jun 22nd

    That is your personal profile url, not your app url.

  7. Mrunali
    Jun 22nd

    This is the application – http://www.facebook.com/apps/application.php?id...
    I made this application show up as tab in profile thinking that way my friends will know about this.

  8. Jun 22nd

    I can see the app, so it's not in sandbox mode. When I try to add it as an app tab to one of my test pages, it doesn't work. It's either a Facebook glicth, or there's something bonkers with your tab code.

  9. Mrunali
    Jun 22nd

    I asked my friend to do the same as you did – she could add it to her test page, here is the link to her page-
    http://www.facebook.com/pages/MyCars/1336510899...

    So I think you are right- until I pass the application id – my friends should be able to see the application and when the user count reaches the required number, I can then publish this page or the application to all to see.

    I think now my thoughts are in the right direction.

    Can you take a look at this page – cars tab? The tabs disappear when I click on the search button. What is that I am missing here?

  10. Jun 22nd

    For the THIRD time – the user count has NOTHING to do with whether or not people can see the app. It only pertains to whether or not it gets listed in the app directory. If your friends cannot see your app tab then either Facebook is acting buggy or there is something wrong with your app.

  11. Will
    Jun 24th

    HOW TO ADD YOUR CUSTOMIZED APPLICATION TAB IN YOUR FAN PAGE:

    To add a Tab (Button) into your managed Fan Page that is connected to your customized Application, view your Application Profile page. At the left side menu, click “Add to Page” then select your Fan Page wherein you want to add your Application to. Go to your corresponding Fan Page and on it's public Tab menu, locate the “+” button. Click it to add your Tab for your customized Application. Then click “>>” to order your Tabs so your customized Application's Tab button will appear within the first 6 Tab button limits.

  12. Will
    Jun 24th

    EXTERNAL SCRIPT ERROR:

    Hope this helps: I discovered when I removed the ff. codes from my external PHP page, the “External Script Error” reported on the bottom of my Fan Page's admin view, disappeared.

    <div id=”FB_HiddenIFrameContainer” style=”display:none; position:absolute; left:-100px; top:-100px; width:0px; height: 0px;”></div>

    <script src=”http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php” type=”text/javascript”></script>

    <script type=”text/javascript”> FB_RequireFeatures(["CanvasUtil"], function(){ FB.XdComm.Server.init(''.$general['docroot'].'/facebook/'); FB.CanvasClient.startTimerToSizeToContent(); }); </script>

    The script above was given by Facebook to be used in combination with the “xd_receiver.htm” file that is related to the iFrame height viewable section on your actual Application's page. Including that file together with the codes above removes the vertical scrollbar from appearing when you've set your Application's Canvas Settings to “resize” instead of “smart size”.

    Thanks for the many articles in this site that have also helped me. :)

  13. Jun 24th

    I posted a video walkthrough several months ago:
    http://www.youtube.com/watch?v=l9bbCVsS9Gg

  14. Jun 24th

    I'm a little confused – app tabs can only be FBML, not IFRAME, so you wouldn't use an xd_receiver there.

  15. Will
    Jun 25th

    When I created my Application, I got confused and never realized that adding it is similar to adding the “Static FBML” app. The non-searchability of my App (because it hasn't been “liked” by many people yet) also contributed to my confusion. hahaha I do not really want my app to be visible in search as it will just act as a Microsite page within a Fan Page. Upon reading this entire thread, I thought the other guy was also asking the same question hence I posted my findings. But thanks for the link and the many useful tutorials. :)

  16. Will
    Jun 25th

    I use my customized Application, which has iFrame, as a Tab within my Fan Page since I think I cannot use iFrame within a “Static FBML” Tab. My customized App is just a simple page that grabs dynamic data from an external website. I just call it as an Application because that is the procedure I went through: Created an Application in Facebook to act as a dynamic page. Since I don't know FBML that well yet (I just know PHP & some MySQL) and I don't have enough time to dedicate to the project, I opted to use an iFrame placed inside a Tab page within a Fan Page. Sorry if my post is confusing. Hope this clarifies it. :D

  17. Jun 25th

    Not really, but i appreciate you trying :) Even in an IFRAME application, the app tab itself is still FBML. If you try to put IFRAME into an app tab, you'll usually get an error.

  18. insightcanada
    Jun 25th

    I'm having a similar issue. I'm trying to pull content from our site and load that into an application that sits as a tab on a page of ours.The actual canvas page of the app works, but its throwing that error when set as a tab.
    Snipe, do you have any ideas of what i might need to do to get a tab that can pull dynamic content from an external site? i thought an iframe would be the magic i needed :P

  19. Jun 25th

    You can pull dynamic content from an external site, but it's gotta be written as an FBML app would be written. Load server-side scripted data, and then call updated information using mock ajax/FBJS.

  20. Thanks for this usefull info “don't lose too much sleep over it either. Most errors are not shown to users, only developers” :^)

  21. Bart
    Jul 30th

    Hi there.
    Totally agree with you after spending hours and hours trying to solve this problem.
    If I'll get it working – I'll let you know as well.

Leave a Reply

Like this site? Buy me a beer!
blog comments powered by Disqus