Skip to content

Instantly share code, notes, and snippets.

@colmdoyle
Created June 22, 2012 00:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colmdoyle/2969543 to your computer and use it in GitHub Desktop.
Save colmdoyle/2969543 to your computer and use it in GitHub Desktop.
A handy script for mass creating instances of an Facebook Open Graph Action. Useful for testing for OAuth errors.
<?php
$access_token = ''; // The access_token you'll use
$app_id = ''; // What AppId are you testing against?
$user_id = ''; // What user are you testing against?
$og_object_url = ''; // The URL of the OG Object
$og_object_type = ''; // OG Object type
$og_namespace = ''; // OG Namespace
$og_action = ''; // OG Action
$post = true; // Are you POSTing or GETing?
$testing_url = 'https://graph.facebook.com/' . $user_id . '/'. $og_namespace . ':' . $og_action . '/?access_token='.$access_token.'&' . $og_object_type . '=' . urlencode($og_object_url); // The URL we will pass (auto-generated)
$control_string = '/(\\{)("id")(:)(").*?(")(\\})/is'; // Your expected string (in regex)
$error_count = 0;
function curl_call($url, $post = false) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_POST, $post);
$payload = curl_exec($ch);
curl_close($ch);
return $payload;
}
for ($i = 1; $i <= 99; $i++) {
$output = curl_call($testing_url, $post);
if (!preg_match($control_string, $output)) {
echo "something went wrong \n";
echo $output;
$error_count++; // Keep a count of when the control string doesn't match the result
echo "\n";
} else {
echo '.';
}
sleep(1); // Hold off for 1 second so we don't freak anyone out.
}
echo "Run Complete. \n There were " . $error_count . " errors detected. ";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment