Skip to content

Instantly share code, notes, and snippets.

@erainey
Created September 29, 2012 18:54
Show Gist options
  • Save erainey/3804893 to your computer and use it in GitHub Desktop.
Save erainey/3804893 to your computer and use it in GitHub Desktop.
PHP: Facebook Send Button Metrics via Graph API
<?php
/***
Facebook Send Button Metrics via Graph API
Originally posted on Facebook Developer Blog by Zhen Fang.
Source: http://developers.facebook.com/blog/post/501
***/
$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$app_domain = "YOUR_APP_DOMAIN"; // e.g. developers.facebook.com
// First, get a valid access token for the app
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $app_id .
"&client_secret=" . $app_secret .
"&grant_type=client_credentials";
$app_access_token = file_get_contents($token_url);
// Query the Graph API for the send views
$graph_url="https://graph.facebook.com/insights/"
. "domain_widget_send_views?"
. "domain=" . $app_domain . "&"
. $app_access_token;
$response = file_get_contents($graph_url);
// Use the results
echo "<pre>";
echo print_r(json_decode($response));
echo "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment