Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [120]

By Root 727 0
my app is serving up 200ND (No Data) or 404 (Not Found) errors.

Solution


Since you can make calls from any server to Facebook through the Client, you can schedule a cron job on your server to use something like curl to request a page that runs the following code:

$hoursAhead = 3;

$appId = 12345;

$appName = 'My App name goes here';

$myEmail = 'me@mydomain.com';

$yesterday = mktime($hoursAhead,0,0,date("m"),date("d")-1,date("Y"));

$query = 'SELECT canvas_page_views_http_code_200ND, canvas_page_views

_http_code_404 from metrics WHERE end_time = ' . $yesterday . ' AND period = 86400;';

$metrics = $facebook->api_client->fql_query($query);

if($metrics && ($metrics[0]['canvas_page_views_http_code_200ND']

> 0 || $metrics[0]['canvas_page_views_http_code_404'] > 0) ){

$headers = 'From: do-not-reply@mydomain.com' . "\r\n" . 'X-Priority: 1';

$message = $appName . ' had ' . $metrics[0]['canvas_page_views

_http_code_200ND'] . ' 200ND errors';

$message .= ' and ' . $metrics[0]['canvas_page_views_http_code_404']

. ' 404 errors';

$message .= ' on ' . date('F dS, Y', $yesterday) . '.';

$message .= ' View more info at http://www.facebook.com/business/

insights/app.php?id=' . $appId . '&tab=httpreq';

$success = mail($myEmail, '[Facebook Errors]: ' . $appName, $message, $headers);

}

?>

The little bit of configuration at the top will customize this for your app.

Discussion


Note that this code requires you to have an SMTP server running locally on your server, which most of you will. You can check to see whether your server’s PHP is at least configured to send mail by putting phpinfo() into a page and loading it in your browser—look for sendmail_path and make sure there’s a value there (you can’t do this through Facebook because phpinfo() outputs a body tag, which the FBML parser won’t allow, so you’ll have to hit your server directly at your callback URL).

Many PHP installs don’t have a default “from” address configured, and most SMTP servers will reject email without one, so we’re adding in an additional header just to be safe (along with setting the priority to the highest level so that you notice the alerts in your inbox).

If you need some help with setting up a cron job, check out Click Mojo’s excellent tutorial at http://www.clickmojo.com/code/cron-tutorial.html.

Event Table


Problem


What’s the schema for the event table?

Solution


The event table holds all of the events created in the Facebook Events application. Its fields are listed in Table 8-5. Queries to this table will only return data the current user is allowed to see (meaning you can’t request events for users the current user isn’t friends with). More information about this table, including an up-to-date listing of fields, can be found at http://wiki.developers.facebook.com/index.php/Event_(FQL).

Table 8-5. event table fields

Name

Type

Index

Description

eid

int

eid (event ID) of this event.

name

string

Name of this event.

tagline

string

Tagline of this event.

nid

int

nid (network ID) of the network, as set by the creator when the event was created.

pic_small

string

URL of the small picture for this event, which has a maximum width of 50 px and a maximum height of 150 px. Might be empty if this field wasn’t set by the creator.

pic_big

string

URL of the big picture for this event (max width of 200 px, max height of 600 px). Might be empty if this field wasn’t set by the creator.

pic

string

URL of the picture for this event (max width of 100 px, max height of 300 px). Might be empty if this field wasn’t set by the creator.

host

string

Name of the host of the event. Note that this can be set to a group when the event is created, but this will return only a string, not a gid.

description

string

Description of this event.

event_type

string

Type of this event. Can be any one of Party, Causes, Education, Meetings, Music/Arts, Sports, Trips, or Other.

event_subtype

string

Subtype of this event. Subtypes are tied to the type, so each type has between 3 and

Return Main Page Previous Page Next Page

®Online Book Reader