-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbdFacebookGraph.php
68 lines (62 loc) · 1.75 KB
/
bdFacebookGraph.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?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 ;
// check for first backslash
if (strpos($getStrGraphRequest, '/') !== 0) {
$getStrGraphRequest = '/'.$getStrGraphRequest;
}
try {
$objFacebookRequest = new FacebookRequest(
$this->FacebookSession,
'GET',
$getStrGraphRequest
);
$arrFBrequest = $objFacebookRequest->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;
}
};
?>