Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [87]

By Root 611 0
name="groups">

global $api_key, $secret;

$facebook = new Facebook($api_key, $secret);

$user = $facebook->require_login();

$groups = $facebook->api_client->groups_get(12345);

foreach($groups as $group){

echo ''. $group['name'] . '';

}

?>

TIP

As with anything marked beta, remember that this might not work the way you expect it to. If you encounter any behavior that looks like a bug, feel free to report it using the Facebook Bug Tracker (http://bugs.developers.facebook.com/).

Using FBML Inside FBJS


Problem


I have a whole big function working perfectly in FBJS, but now I want to use some FBML as an output inside of it. Putting the FBML into the FBJS directly doesn’t work, so how can I get it in there?

Solution


Use the fb:js-string tag. The simplest form is:

Any FBML you put inside the fb:js-string tag will become available in the FBJS on your page as the variable named in var (in this case, I’d now have a variable in my FBJS called myName with the value “Jay Goldman”).

Discussion


This tag comes in handy when you want to do things like display a bunch of content or a number of options inside something like a dialog (see Dialogs That Pop) using FBJS:

What's your favorite ice cream flavor?

That will give you something like Figure 6-51.

Figure 6-51. FBJS dialog using fb:js-string

NOTE

There’s an easier way to create this particular example if you don’t need to do it from inside FBJS—just use the fb:dialog tag. See Dialogs That Pop for more info.

Dialogs That Pop


Problem


I need to show my users some information in a way that really grabs their attention. I’ve seen some pop-up dialogs around Facebook that are like overlays (rather than JavaScript alerts) and I really dig ’em. Especially the semi-transparent smoky edges!

Solution


Another great example of FBML making something complicated really simple. Use the fb:dialog tag to show a simple pop up with some content:

I Scream! You Scream! We All Scream!

For Ice Cream!

which will give you Figure 6-52.

Figure 6-52. Simple fb:dialog

Notice the very important clicktoshowdialog attribute on the button, which tells Facebook to trigger the dialog when the button gets clicked.

Discussion


The clicktoshowdialog attribute can be applied to things that typically aren’t clickable, such as divs:

Click Me!

The fb:dialog-content tag can contain entire forms if you want to do something more than just display info to your users. For example, the following:

I Scream! You Scream! We All Scream!

What's your favorite flavor?

form_id="ice_cream_flavors"

Return Main Page Previous Page Next Page

®Online Book Reader