-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacebookHelp.php
103 lines (84 loc) · 2.57 KB
/
FacebookHelp.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
require_once __DIR__ . '/vendor/autoload.php';
/**
*
*/
class FacebookHelp {
private static $fbHelp;
private $app_id, $app_secret, $graph_version, $access_token;
private $session;
private function __construct($app_id, $app_secret, $graph_version, $access_token) {
$this->app_id = $app_id;
$this->app_secret = $app_secret;
$this->graph_version = $graph_version;
$this->access_token = $access_token;
}
public static function newInstance($app_id, $app_secret, $graph_version, $access_token) {
if (self::$fbHelp == null)
return (self::$fbHelp = new FacebookHelp($app_id, $app_secret, $graph_version, $access_token));
return self::$fbHelp;
}
public function generateSession() {
if ($this->app_id == NULL || $this->app_secret == NULL ||
$this->graph_version == NULL || $this->access_token == NULL)
return false;
if ($this->session == NULL) {
$this->session = new Facebook\Facebook([
'app_id' => $this->app_id,
'app_secret' => $this->app_secret,
'default_graph_version' => $this->graph_version,
]);
$this->session->setDefaultAccessToken($this->access_token);
}
return $this->session;
}
public function requestGraphNode($request) {
try {
$response = $this->session->get($request);
$graphNode = $response->getGraphNode();
}
catch (Facebook\Exceptions\FacebookResponseException $e) {
return NULL;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
return NULL;
}
return $graphNode;
}
public function requestGraphUser($request) {
try {
$response = $this->$session->get($request);
$graphUser = $response->getGraphUser();
}
catch (Facebook\Exceptions\FacebookResponseException $e) {
return NULL;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
return NULL;
}
return $graphUser;
}
public function requestGraphEdge($request) {
try {
$response = $this->session->get($request);
$graphEdge = $response->getGraphEdge();
}
catch (Facebook\Exceptions\FacebookResponseException $e) {
return NULL;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
return NULL;
}
return $graphEdge;
}
public function requestGraphPicture($request) {
try {
$response = $this->$session->get($request);
$graphPicture = $response->getGraphPicture();
}
catch (Facebook\Exceptions\FacebookResponseException $e) {
return NULL;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
return NULL;
}
return $graphPicture;
}
}
?>