Created
July 29, 2011 08:25
-
-
Save fordnox/1113440 to your computer and use it in GitHub Desktop.
Very simple Facebook graph executor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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