Home > Articles > Home & Office Computing > The Web/Virtual Worlds/Social Networking

The Developer's Guide to Social Programming: Application Discovery, Tabbed Navigation, and the Facebook JavaScript Library

This chapter explores how you can use dashboards in your Facebook Platform application through the Dashboard API and how you can use application tabs as a way of sharing your application's information with users and their friends.
This chapter is from the book

Facebook can be used as a mechanism for sharing content, commenting, and stream publishing, as you learned in Chapter 7, "Using Facebook Connect for Sharing, Commenting, and Stream Publishing." However, the Facebook environment contains three other ways in which users and their friends can interact: application dashboards, which focus on the discovery and reengagement of games and applications; counters, for alerting users that they need to take action on an application or game (perhaps taking their next turn) or that a report is ready for them to view; and application tabs, which can be shown on a user's profile alongside other profile information. These three channels can be used by a Facebook Platform application to engage users both within and outside of Facebook.

This chapter explores how you can use dashboards in your Facebook Platform application through the Dashboard API. Through the Dashboard API, you can post news items to a user's dashboard, promote friends' activities, and utilize activity counters. The second part of this chapter focuses on application tabs as a way of sharing your application's information with users and their friends. Following the deprecation of profile boxes, application tabs are the only mechanism for enabling users to personalize their profiles and showcase their favorite applications. This section includes details about how to configure, install, and develop an application tab through the use of "Mock AJAX". The final section showcases Facebook JavaScript (FBJS) and how you can use it for events, animations, and Facebook dialogs.

Application Dashboards and Counters

Because of the popularity of social gaming applications on Facebook, their recent redesigns have started to put more emphasis on highlighting specific features for games. There are now two types of "dashboards": Games (http://www.facebook.com/?sk=games) and Applications (http://www.facebook.com/?sk=apps). These are accessible via a user's home page alongside bookmarks. The goal of each of the dashboards is to make it easier for Facebook users to access games or applications that they or their friends have recently used and to discover new applications through their friends or the Application Directory (see Figure 8.1).

Figure 8.1

Figure 8.1 Screenshot of the Games dashboard.

Various key features are available within the dashboards:

  • Recently used applications or games display right at the top so that users can quickly and easily find applications they use on a daily basis. The number of friends who also use the application is also highlighted next to each application's title.
  • News items can be used to allow applications to communicate with users either to display news to all users or alert individual users that they need to take action. For example, a game news item may say "It's your turn to play, Mark!" You can also use news items to mention a user's friends and invite them to play a game with you.
  • A user's friends' recent activity is shown, which is used to promote applications and games that a user might not have installed. This can also be toggled to display the activities that an individual has recently completed, which can be privacy controlled.
  • A list is maintained of all friends who recently interact with applications that appear below the activities. These take the form of a list and are updated dynamically based on usage.
  • The legacy Facebook Application Directory is displayed right at the bottom of the dashboards for searching for applications in particular categories. When submitting your own application to the directory, this will be the category or categories that you have provided.
  • Facebook also runs features on particular applications or sponsored applications, which are shown to the right side of a profile. These are generated by combining a users' and their friends' activities to suggest the most suitable applications or games to their profile.
  • Counters can be shown alongside an application's name for games or applications that a user has bookmarked. These are discussed further in the "Games and Applications Counters" section, later in this chapter.

When submitting an application to the directory, a developer will choose whether the application should be listed as a "game" or as a regular "application." This designation dictates which dashboard it will be placed within. Both dashboards contain the same functionality and so differ only in content. A new Dashboard API was released in February 2010 to encompass all the features of dashboards (the subject of the remainder of this section), including adding to news and activity streams and updating counters.

News and Activity Streams

As you have seen in the Games and Application dashboards, Facebook has concentrated a lot of their efforts on keeping users updated as to what they and their friends are up to. One of the main ways in which this is achieved is through activity streams. Activities are reported on the Games and Application dashboards in two distinct ways, through news and activities:

  • News items can be set to display global and personal items to an individual or set of individuals. These could be that a new feature has been added to your game or application or if a friend has initiated an action involving a particular user.
  • Activity items display actions performed specifically by the individual that appear in that individual's stream but could also reference one of their friends. In which case, that individual's activity will also appear in a friend's news items.

The methods for each of these streams are similar to those regarding stream publishing discussed in Chapter 7. The only real difference here is that news and activities are restricted to the dashboards rather than the user's stream, which helps to reduce unnecessary clutter.

Working with News Items

News items are a way of sharing announcements with your users or for indicating that a friend has performed an activity that has referenced them. There are two types of news items, global and personal, depending on what method was called to create the item. Facebook displays just two news items within either the Games or Applications dashboard, and so they also provide a convenient method to clear news items from a user's stream.

Adding News Items

News items can be added using the following methods either individually, globally, or for multiple individuals using the following:

  • dashboard.addNews
  • dashboard.addGlobalNews
  • dashboard.multiAddNews

Each method requires a slightly different set of parameters, such as providing a uid (which is that of the user whose dashboard you are updating) for individual news and which is not required for global news items. For updating multiple users, an array of uids is required instead. This array contains a number of user identifiers that require updating. Note that you cannot set multiple messages for each of these individuals, so each news item will be the same for each of the identifiers you provide. An array of up to eight news items is also required. This must contain a message and an optional action_link that includes text and a href. If you want, you can also supply an optional image parameter. This must be an absolute URL that is formatted as a 64x64px square. An example of each method is shown here:

$user = $facebook->get_loggedin_user();
$users = array("1", "2", "3");
$news = array(
 array(
  "message" => "Hey, {*actor*}. Your friend @ just invited
  you to play chess.",
  "action_link" => array (
   "text" => "Play Now!",
   "href" => "http://myfacebookapp.com/?game=chess"
  )
 )
);
$global_news = array(
 array(
  "message" => "Hey, {*actor*}. There is a new game to play, chess.",
  "action_link" => array (
   "text" => "Play Chess!",
   "href" => "http://myfacebookapp.com/?game=chess"
  )
 )
);
$image = "http://29.media.tumblr.com/avatar_abad48dbd089_96.png";
$individual_news = $facebook->api_client->dashboard_addNews($user, $news,
$image);
$global_news = $facebook->api_client-
>dashboard_addGlobalNews($global_news, $image);
$multi_news = $facebook->api_client->dashboard_multiAddNews($users, $news, $image);

If successful, the $global_news and $individual_news items will return a news_id if the call succeeds, and the $multi_news item will return an associative array of uid keys that contain either a news_id if successful or false if unsuccessful. These news_id values are important and should be stored because they will be required if news items need to be cleared from a dashboard. In addition, two conventions were demonstrated in the message values: You can use the {*actor*} token, which is also available within stream attachments, to be rendered as the user whose dashboard is being updated; and you can use <<USER_ID>>, where <<USER_ID>> can be replaced by any user identifier. In your own applications, this would form part of a two-stage process of updating an individual's activity stream but also updating the news streams of that user's friends that he or she was playing against or wanting to update.

Clearing News Items

As with adding news items, three methods enable you to clear updates that have already been created by an application. Clearing individual news will not remove global news and vice versa, and so these methods may be used alongside each other:

  • dashboard.clearNews
  • dashboard.clearGlobalNews
  • dashboard.multiClearNews

All of an individual's news items can be removed by using the dashboard.clearNews method and supplying their uid as the single required parameter or by additionally passing in an array of news_id values. For global news, the dashboard.clearGlobalNews method can be called without any parameters to remove all news or can include an array of news_id values similar to the individual news item method. Clearing multiple individuals' news items is slightly more complex. Here is an example assuming that the $multi_news parameter that was presented in the "Adding News Items" section above returned the following:

$multi_news = array(
 "1" => 111,
 "2" => 222,
 "3" => 333
);
$ids = array(
 "1" => array("111"),
 "2" => array("222"),
 "3" => array()
);
$removed_multi_news = $facebook->api_client->dashboard_multiClearNews($ids);

A successful response from the individual and global methods is an associative array of news_id keys and Boolean values depending on whether the news item has been removed. When you are removing multiple individuals' news items, an associative array will be returned equivalent to the individual and global methods if news_id values were supplied. Otherwise, if no news_id values were supplied (such as the last $ids parameter), an associative array will be returned containing the uid as the key and a Boolean value of whether the news item was removed or not.

Getting News Items

The final sets of methods are used to extract a user's or group of users' news streams. Simply put, these methods provide you with the original news and image values that were set when adding news items. The method names are as follows:

  • dashboard.getNews
  • dashboard.getGlobalNews
  • dashboard.multiGetNews

These methods prove particularly useful should you not want to store news_id values within your database of file stores.

Working with Activity Items

Unlike news items, activity items are an experimental feature and may be removed by Facebook in the future. Activity streams are used to broadcast to a user's friends what that user been up to within a game or application (for example, posting high scores or whether the user has uploaded new files or photos). There are only three methods for working with activity items, and these cannot be called for multiple individuals like news items:

  • dashboard.getActivity

    This method will return the latest 100 activities recorded for the current user. The method can be called with an optional activity_ids array if you have recorded each activity_id for your users.

  • dashboard.publishActivity

    This method works in exactly the same way as dashboard.addNews, but rather than being a news object, it is an activity. The same conventions for using {*actor*} and <<USER_ID>> tokens can be used when setting activity items. Successful publishing of an activity will return a numeric activity_id.

  • dashboard.removeActivity

    Activities can be removed by supplying an array of activity_id values, which will return an associative array of activity_id keys and a Boolean value indicating success or failure.

When setting up your application in Chapter 5, "An Overview of Facebook Platform Website Integration," you may have noticed a setting called Hide User Activity within the "Advanced" tab. This setting can be checked if you think that your application will generate activities that a user might want to keep private and not share with friends. Although further details were not available at the time of this writing, Facebook intends to give users sufficient control over which news and activity items they both send and receive. Like items being posted to their stream, it may be that they want to inform certain friends of their activities but exclude others.

Games and Applications Counters

Before an application or game can utilize counters, it must first be bookmarked by the user. This can be done from within Facebook using the links provided on each of the dashboards. However, it can also be facilitated through embeddable <fb:bookmark> FBML and XFBML tags. A bookmark URL must be set. You can find this within the "Basic" tab of an application; otherwise, the application's connect URL or canvas page URL will be used. For Facebook Platform applications, you can set the type attribute of the button to off-facebook, which will render a blue button in place of the standard gray used within canvas applications. Upon clicking the button, users are prompted with a dialog box to add the application to their profile (see Figure 8.2).

Figure 8.2

Figure 8.2 Example bookmark dialog for theTest Tube application.

If a user has already bookmarked your application, the button will not appear. You can also check this by querying the permissions FQL table, as follows:

$bookmarked = $facebook->api_client->fql_query('
 SELECT uid, bookmarked
 FROM permissions
 WHERE uid = "'.$official_user.'"
');

The result of this FQL query will be either a 1 or a 0 that can be extracted by using $bookmarked[0]["bookmarked"]. New bookmarks will appear underneath the links to the Games and Applications dashboards and can be rearranged by users after clicking the "More" link below their bookmarks. After an application has been bookmarked, you can start exploiting the features of counters via the Dashboard API.

There are two types of counter methods. One type of method enables you to update an individual's counter. The other type of method can be used to update a number of individuals' counters. Users could utilize this to let a group of friends know of an action they've taken in a game and that it is now their turn. There are four methods for updating the first type of counter for individuals:

  • dashboard.decrementCount
  • dashboard.getCount
  • dashboard.incrementCount
  • dashboard.setCount

These methods can be run either using the logged-in user's credentials or by supplying a uid alongside your application secret. Unlike internal Facebook applications or games, when using website integration you must ensure that every time a user visits your bookmark URL that the user's counter is reset to zero. For applications that want to update a group of individuals' counters at the same time, the second type of counter method, a number of batch methods are available:

  • dashboard.multiDecrementCount
  • dashboard.multiGetCount
  • dashboard.multiIncrementCount
  • dashboard.multiSetCount

These batch methods all request that an array of uids be supplied and will return an array of uids as the key and a Boolean value for whether the request was successful. It is suggested that when users visit your application, either on a canvas page or via an external website, that their counter is set to zero to ensure that users do not get confused as to what actions they are required to take.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020