Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [138]

By Root 760 0
can make the calls to generate them). See Recipes

Logging Out


Problem


How can I give my users a way to log out of Facebook?

Solution and Discussion


Just send them to http://www.facebook.com/logout.php?confirm=1.

Getting Allocations


Problem


I need to retrieve my allocations from Facebook so that I know how many Notifications I can send out per day.

Solution


Use the Admin.getAllocations() method:

$allocation = $facebook->api_client->admin_getAllocation('notifications_per_day');

Discussion


This method supports retrieving a number of different allocations, as shown in Table 9-3.

Table 9-3. Allocations

Allocation

Description

notifications_per_day

Number of Notifications your application can send per user per day

requests_per_day

Number of requests your application can send per user per day

emails_per_day

Number of email messages your application can send to a user per day

email_disable_message_location

Location of the disable message within emails sent by your application (“1” is at the bottom and “2” is the top)

For more information about allocations, see Understanding Allocations.

Getting Metrics


Problem


I want to retrieve my app’s daily metrics for yesterday.

Solution


The Admin.getMetrics() method will return metrics for daily, weekly, or monthly periods:

$targetMetrics = array('active_users');

$monthAgo = strtotime('yesterday') - 24*60*60*29;

$yesterday = strtotime('yesterday');

$oneDay = $facebook->api_client->admin_getMetrics($monthAgo,

$yesterday, 86400, $targetMetrics);

$sevenDays = $facebook->api_client->admin_getMetrics($monthAgo,

$yesterday, 604800, $targetMetrics);

$thirtyDays = $facebook->api_client->admin_getMetrics($monthAgo,

$yesterday, 2592000, $targetMetrics);

Discussion


Admin.getMetrics() accepts start and end dates, expressed in epoch time, a period, and an array containing a list of the specific metrics you’re looking for (you have to use an array, even if you only want one back, or you’ll get a long error message about needing an array). The period parameter, also expressed in epoch seconds, defines the period you want to receive metrics for: one day (86400 seconds), seven days (604800 seconds), or 30 days (2592000 seconds). See Formatting Relative Time for more information about epoch time. Your return value will always be a multidimensional array (which makes sense, since you’re requesting an array), with each item containing a date and the specified metric. If you requested a one-day period of active_users and did a PHP print_r on that array, you might see:

Array

(

[0] => Array

(

[active_users] => 1234340

)

)

There are quite a few metrics you can request for your app (see Table 9-4), based on what you can graph on the Usage and HTTP Requests tabs of the Facebook Insights application (for more info, see Measuring Your Success).

Table 9-4. Metrics

Metric

Description

active_users

Active users

unique_adds

Users who added your application

unique_removes

Users who removed your application

unique_blocks

Users who blocked your application

unique_unblocks

Users who unblocked your application

api_calls

API calls made by your application

unique_api_calls

Users on whose behalf your application made API calls

canvas_page_views

Canvas page views

unique_canvas_page_views

Users who viewed your application’s Canvas page

canvas_http_request_time_avg

Average time to fulfill an HTTP request to your application’s Canvas page

canvas_fbml_render_time_avg

Average time to render FBML on your application’s Canvas page

canvas_page_views_http_code_0

Canvas page views that timed out

canvas_page_views_http_code_100

HTTP code 100s—Continue

canvas_page_views_http_code_200

HTTP code 200s—OK

canvas_page_views_http_code_200ND

HTTP code 200s—OKs with no data

canvas_page_views_http_code_301

HTTP code 301s—Moved Permanently

canvas_page_views_http_code_302

HTTP code 302s—Found

canvas_page_views_http_code_303

HTTP code 303s—See Other

canvas_page_views_http_code_400

Return Main Page Previous Page Next Page

®Online Book Reader