Skip to content

Commit

Permalink
:D
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryDam committed May 9, 2014
1 parent a2111fd commit bc5d861
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions bdFacebookGraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
use FaceBook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;

class bdFacebookGraph
{
private $APP_ID = false,
$APP_SECRET = false,
$FacebookSession = null
;

/**
* @param $getAppID Facebook App ID
* @param $getAppSecret Facebook App Secret
*/
public function __construct($getAppID, $getAppSecret)
{
$this->APP_ID = $getAppID;
$this->APP_SECRET = $getAppSecret;
//set the facebook session
$this->setSession();
}

private function setSession()
{
$strAccesToken = $this->APP_ID.'|'.$this->APP_SECRET;
$this->FacebookSession = new FacebookSession($strAccesToken);
if (! $this->FacebookSession)
throw new Exception("Can not set Facebook Session with access token $strAccesToken", 1);
}

public function fetchByRequest($getStrGraphRequest = false)
{
if (! $getStrGraphRequest) return ;
try {
$arrFBrequest = (new FacebookRequest(
$this->FacebookSession,
'GET',
$getStrGraphRequest
))->execute()->getGraphObject()->asArray();

} catch (FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
return $this->convertRequestResultToArray($arrFBrequest);
}
private function convertRequestResultToArray($a = false)
{
// convert when its an object
if (is_object($a)) {
$a = get_object_vars($a);
}
// deeplink when array
if (is_array($a))
return array_map(array($this, 'convertRequestResultToArray'), $a);
else
return $a;
}

};
?>

0 comments on commit bc5d861

Please sign in to comment.