KMart's Birthday Club

I recently finished working on KMart’s Birthday Club website, a wordpress-based children’s site that is geared towards parents looking to make their child’s special day memorable.  My role was handling all the social media aspects required in the project plan.

One of the bigger problems I ran into with this – I really didn’t like any of the existing facebook plugins for WordPress, so I ended up building my own.  It was really an interesting learning experience.  This gave me the opportunity to dig deeper into the new facebook Graph API than I have in the past, and it wasn’t as terrible as the facebook API once was.

My largest, and most interesting task, was to pull down photo-galleries and create a taxonomy for each one.  The interaction with facebook for pretty much everything I had to do was fairly simple:

/**
 * Fetches data from facebook API
 *
 * @author Jason Corradino
 *
 * @param $path (required) facebook query path
 * @param $format (optional) format data is returned as either an object or json [obj|json]
 * @param $attr (optional) Adds additional attributes to the URL
 *
 * @return returns object of facebook data by default, json if 'format' parameter is set to json
 *
 */
static function getData($path, $format="obj", $attr="") {
	$pluginOptions = get_option('facebook_gallery_options');
	$token = $pluginOptions["token"] ? $pluginOptions["token"] : FACEBOOK_APP_TOKEN;
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/".$path."?access_token=".$token."&api_key=".FACEBOOK_API_KEY."&".$attr);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$return = curl_exec($ch);
	curl_close($ch);
	return ($format == "json") ? $return : json_decode($return);
}

The above code will use your facebook application token to open up a curl with the facebook graph API, pulling down the requested data set within the URL, returning in the format set within the function call — defaulting to an object, but allowing a JSON response.

There will be a more detailed post about this down the line, and I am considering releasing the plugin I built to wordpress.org extend. So look forward to that.

Happy coding