Random questions

From Facebook Developer Wiki

Jump to: navigation, search

If you have a random technical question, look for it here, and if you don't find it, post your questions to our IRC channel.



Contents

[edit] Error : Executing My Application

How to set FBML support for my application? When I choose the 'Use FBML' option while setting up my new application, then it occurs an 'invalid url' error while executing the application. When I choose 'Use iframe', the application executes but can not use FBML although using setFBML() function. What is the reason?

Answer: try to place your <html> tags w/ the <fb:fbml></fb:fbml> tags. I don't think it works without that.

[edit] fb:ref

How do we get the fb:ref cache to clear?

I'm unclear what "Through Key/Value Pairs" and everything underneath means on this page. (And I'm a computer engineer) Can someone expand on it?

Answer: Key/Value pairs is an easy way to store FBML that you use within your application. For example, should I want to store the basic FBML '<fb:name/>', I could store it under the key "UsersName", by calling:

facebook.fbml.setRefHandle("UsersName", "<fb:name/>")

I could then place that content on the page by writing:

<fb:ref handle="UsersName" />

Obviously this is more useful for more complex FBML.
Presumably, to clear the cache you simply call:

facebook.fbml.setRefHandle("UsersName", "")

[edit] Edit About Page Error

I try to save changes to my app's about page and get the following error: Your company name cannot include the word "Face" even thought Face isn't anywhere in the name.

Answer: That is not an error message, rather it is static text on the page. Your changes are saved despite the error that you are seeing.

[edit] Storing data

The FAQ questions on what data can be stored have bad links to the terms of service. The TOS in turn says that what data can and cannot be stored is in the developer docs. I can't find it there! Where is it?

Answer: See the document on storable information. According to this document, an application may persist only certain Facebook ID keys. All other information must be queried from the Facebook API at runtime.

Also, somewhere it suggests that we are allowed to store userids. Does this mean that we are allowed to store information about which user ids are friends with which others? Thanks!

Answer: The storable information document also describes the relationships between IDs that may be persisted. In particular, storing friendships is not allowed. The intent seems clear: Facebook does not want developers to recreate the Facebook friend graph database. Friendships must be queried at runtime using facebook.friends.get().

Don't you need to have a session key to do that?

Answer: Yes. But session keys are easy to obtain using the api or via canvas pages. It follows that the API may only be utilized on behalf of a user currently logged into Facebook.

According to storable information, I may cache data for up to 24 hours. If I obtain infinite sessions from users, am I allowed to refresh that cached information every < 24 hours, thus not violating the TOS?

Answer: Yes. You should be able to do this for performance of your application. Please note that you must purge anything stored after 24 hours.

I was wondering what happens if you would like to export information for reporting purposes where there is no direct link back to the userid. Is the exporting or storing of information that has had its link severed from the userid possible? (I second this question! Any answer to this?)

So, a user invites another one to use/install an application. Can we store the information about whom the user sent invitation to, and track the information about whether a user installed the application that's sent her by another user?

[edit] Adding Info

Pray tell, how do some of the applications add info to an user account? I want to try make a scrobbler just to test and see how it all works together.

Answer: They store the data on their own servers in a MySQL database, as seen in the example application.

[edit] Message attachments

Can anyone shed some light on how message attachments work? I can't find any documentation on this!

There is some basic documentation at the bottom of this page: http://developers.facebook.com/documentation.php?v=1.0&doc=installation

Basically, you need to have a < input type="hidden" name="url" value="your attachment URL here" > in the callback page for your attachment. However, it doesn't seem to work very well; according to my experience, Facebook is returning incorrect form values to that URL. The application GlitterText seems to have made it work, though, so you might want to look at that.

http://developers.facebook.com/documentation.php?v=1.0&doc=installation is useless when it comes to what it exactly needed to call. It is too vague to know what is needed and if it does not work, there is no good way to debug what goes wrong. Anyone has better success?

Have you checked out this page: Attachment_Example?

I have checked out the Attachment_Example, I apparently didn't understand it well enough as it didn't work. Could you provide a working example of it so that we can see it in action? Either that or make it more clear EXACTLY what needs to be done.

[edit] Profile Actions

I see that <fb:profile-action> can cause a link to surface on a user's profile page. Unfortunately, it does not appear to affect the profile summary that is seen in a friend list, for example. Built-in applications appear to be able to add such links - "View Videos" comes to mind. Have I missed something?

Answer: The <fb:profile-action> only shows a link in the users profile page. None of the applications add a link to the summary. The video one may show up because it was created by Facebook. Note: I assuming by summary you mean what is shown when you click "See All" under the "Friends at <some network"> area in the profile.

[edit] Infinite Sessions

I simply want a good way to get whether or not an infinite session is still in service, without making unnecessary queries. users.getLoggedInUser would seem like the obvious choice, but it doesn't work. Any ideas?

My Answer: Use users.getInfo and only pass the current uid as a field. Obviously this is not ideal, any chance of an API update?

Answer: Use the ADD page to store a new users session_key and whether it is infinite for every new user. Use facebook.users.getInfo to obtain 'has_added_app' and find if the user is an app member. If has_app_added == 1 then you can always use the infinite session_key you have stored. If has_added_app == 0 then the user has removed your app and the session_key is out of date.

More information about infinite sessions can be found here.

[edit] Basic Application Architecture

Q: What is my server supposed to be doing? If I'm just calling an API call, why can't my FBML call it directly?

A: FBML is just fancy markup. The server *has* to do business logic. It calls the APIs on Facebook and produces (typically) FBML as a result, which is then presented to the user. Javascript is not used to create markup using Ajax-style calls to the facebook system. See also: mock ajax.

The following is an example flow for how the HTML for a web app canvas is rendered:



                           +------------------+
                           |   BROWSER        |
                           |                  |
                           |   +-------------+|
                           |   |Application  ||
                           |   |Canvas       ||
                           |   |             ||
                           |   |             ||
                           |   +-------------+|
                           |                  |
                           +---+----------+---+
                               |          ^
             1) Browser makes  |          | 5) Facebook Renders FBML to
                      request  v          |    HTML
                         +-----+----------+-----+
                         | FACEBOOK SERVER      |
                 +-------+                      |
                 |       |                      |
                 |       |                      |
                 |       |                      +<-------------+
                 |       |                      |              |
                 |       |                      |              |
                 |       |                      |              |
                 |       |                      |              |
                 |       |                      |      4) App Server
        2) FB Server Calls                      |       Returns FBML
          out to App Server---------+-----------+              |
                 |                  ^                          |
                 |                  | 3) App calls FB API      |
                 |                  v                          |
                 |        +---------+------------+             |
                 |        | YOUR APP SERVER      |             |
                 |        |                      |             |
                 |        |                      |             |
                 |        |                      |             |
                 +------->+    2.5) App server   +-------------+
                          |       composes API   |
                          |       calls          |
                          |                      |
                          |    3.5) App server   |
                          |       generates FBML |
                          |       from API results
                          +----------------------+


On profile pages, it looks more like this. Here, the app pushes FBML to the profile asynchronously, which is accomplished using fb:ref(see related forum post and blog post). That FBML can have Flash which can dynamically pull from the app server, and there are other ways (such as dynamic images or mock ajax) to pull content from the app server from the profile box:



                           +------------------+
                           |   BROWSER        |
                           |                  |
                           |   +-------------+|
                           |   |Profile Box  ||
                           |   |             ||
                           |   |             ||
                           |   |             ||
                           |   +-------------+|
                           |                  |
                           +---+----------+---+
                               |          ^
             1) Browser makes  |          | 2) Facebook Renders FBML to
                      request  v          |    HTML
                         +-----+----------+-----+
                         | FACEBOOK SERVER      |
                 +------>+                      |
                 |       |                      |
                 |       |                      |
                 |       |                      |
                 |       |                      |
                 |       |                      |
                 |       |                      |
                 |       |                      |
                 |       |                      |
        0) App server pushes                    |
          FBML to Facebook  --------------------+
        Server based on App
        Event (Asynchronous)
                 |        +----------------------+
                 |        | YOUR APP SERVER      |
                 |        |                      |
                 |        |                      |
                 |        |                      |
                 +--------+                      |
                          |                      |
                          |                      |
                          |                      |
                          |                      |
                          |                      |
                          |                      |
                          +----------------------+


[edit] Funny Eyes

Can I do something like http://javascript.internet.com/miscellaneous/eyes.html in fbml or whatever?

  • It would probably have to be flash, js isn't allowed (thank goodness) (42904324 10:50, 21 June 2007 (PDT))
    • Ewwww.. why?? --8618024 17:27, 26 June 2007 (PDT)
    • Why JS is not allowed ?
    • It's facebook policy - my guess being it's a) dangerous and b) annoying. The same reason profiles are push-only, and flash is click-to-play. --42904324 10:16, 29 June 2007 (PDT)
      • And the same reason why Myspace is UE hell and facebook is not --570785920 04:18, 7 July 2007 (PDT)
        • JavaScript isn't annoying :P AJAX wouldn't be possible without JS. The reason for not allowing it is to prevent worms & viruses like the MySpace worm.
          • Okay, correction. JS isn't annoying...but it can be. So FB allows certain useful JS stuff, but disallows anything else. --42904324 17:01, 9 July 2007 (PDT)

Also, if you want to use your own javascript; simply do a iframe. Then you have full reign. CORRECTION: JavaScript is allowed in the new FB API.

[edit] URLs in my application

Q: What URLs does my application have to support? How are HTTP calls to facebook converted into HTTP calls into my application?

A: All calls to http://app.developer.com/yourapp/<somepath> are rewritten to (your app server is example.com) http://example.com/canvasurlpath/<somepath>, and the returned html (without <html>, <head>, <body>, etc and with FBML) is rendered inside the Facebook canvas.

For example, http://app.developer.com/yourapp/foo.jsp would be rewritten to http://example.com/canvasurlpath/foo.jsp

[edit] Display content from profile.getFBML on the Canvas

Q: I want to display the current data for the user at the canvas via profile.getFBML but all the content is hidden in the <fb:narrow> and <fb:wide> tags. How to I display it? Is there something like <fb:canvas>?

A: You can use the following hack while posting the data with profile.setFBML:


<fb:switch>
<fb:wide>$fbml_wide</fb:wide>
<fb:narrow>$fbml_narrow</fb:narrow>
<fb:default>$fbml_canvas</fb:default>
</fb:switch>

It will display the code from <fb:default> at the canvas.
Thanks to Blackbox from the forum. http://forum.developers.facebook.com/viewtopic.php?id=1734

reference