Skip to content

Instantly share code, notes, and snippets.

@fordnox
Created July 29, 2011 08:25
Show Gist options
  • Save fordnox/1113440 to your computer and use it in GitHub Desktop.
Save fordnox/1113440 to your computer and use it in GitHub Desktop.
Very simple Facebook graph executor
<?php
namespace Ai;
class Facebook
{
private $token;
public function __construct($token)
{
$this->token = $token;
}
/**
* Call facebook graph for info
*
* @example
*
* $fb = new \Ai\Facebook($access_token);
* $details = $fb->me();
* $details = $fb->me_friends();
* $details = $fb->me_notes();
*
* @see http://developers.facebook.com/docs/reference/api/
* @return stdClass
*/
public function __call($name, $arguments)
{
$url = str_replace('_', '/', $name);
$graph_url = sprintf('https://graph.facebook.com/%s?access_token=%s', $url, $this->token);
$r = @file_get_contents($graph_url);
$response = json_decode($r);
if(!is_object($response)) {
throw new \Exception('Wrong response from Facebook: '.$r. ' URL: '.$url);
}
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment