|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: RocketCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 30.04.2018 |
|
25
|
|
|
* Time: 01:14 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
namespace Plugin\FacebookApi; |
|
29
|
|
|
|
|
30
|
|
|
use Facebook\Facebook; |
|
31
|
|
|
use Facebook\Exceptions\FacebookResponseException; |
|
32
|
|
|
use Facebook\Exceptions\FacebookSDKException; |
|
33
|
|
|
use Facebook\GraphNodes\GraphPage; |
|
34
|
|
|
use Facebook\GraphNodes\GraphNode; |
|
35
|
|
|
|
|
36
|
|
|
class Page { |
|
37
|
|
|
|
|
38
|
|
|
protected $fb = null; |
|
39
|
|
|
protected $api = null; |
|
40
|
|
|
|
|
41
|
|
|
protected $pageID = ""; |
|
42
|
|
|
|
|
43
|
|
|
protected $response = null; |
|
44
|
|
|
protected $graphNode = null; |
|
45
|
|
|
protected $page = null; |
|
46
|
|
|
|
|
47
|
|
|
public function __construct (FacebookApi $api) { |
|
48
|
|
|
$this->fb = $api->getSDK(); |
|
49
|
|
|
$this->api = $api; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function loadPage (string $name) { |
|
53
|
|
|
$this->pageID = $name; |
|
54
|
|
|
|
|
55
|
|
|
//https://stackoverflow.com/questions/7633234/get-public-page-statuses-using-facebook-graph-api-without-access-token |
|
56
|
|
|
|
|
57
|
|
|
//get all available fields: /{page-id}?metadata=1 |
|
58
|
|
|
|
|
59
|
|
|
try { |
|
60
|
|
|
// Returns a `Facebook\FacebookResponse` object |
|
61
|
|
|
$this->response = $this->fb->get( |
|
62
|
|
|
"/" . $this->pageID . "?fields=id,about,fan_count,website,location,name,username,phone,feed.limit(10){child_attachments,application,actions,caption,description,expanded_height,created_time,coordinates,comments_mirroring_domain,backdated_time,event,from,feed_targeting,full_picture,id,is_expired,is_hidden,height,is_popular,is_published,message,message_tags,likes,link,picture,properties,scheduled_publish_time,object_id,type,privacy,name,place,reactions,permalink_url,shares},band_members,best_page,band_interests", |
|
63
|
|
|
$this->api->getAccessToken() |
|
64
|
|
|
); |
|
65
|
|
|
} catch(FacebookResponseException $e) { |
|
66
|
|
|
echo 'Graph returned an error: ' . $e->getMessage(); |
|
67
|
|
|
exit; |
|
|
|
|
|
|
68
|
|
|
} catch(FacebookSDKException $e) { |
|
69
|
|
|
echo 'Facebook SDK returned an error: ' . $e->getMessage(); |
|
70
|
|
|
exit; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->graphNode = $this->response->getGraphNode(); |
|
74
|
|
|
$this->page = $this->response->getGraphPage(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function listFieldNames () : array { |
|
78
|
|
|
return $this->graphNode->getFieldNames(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getGraphNode () : GraphNode { |
|
82
|
|
|
return $this->graphNode; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getGraphPage () : GraphPage { |
|
86
|
|
|
return $this->page; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getID () : int { |
|
90
|
|
|
return $this->getGraphNode()->getField("id"); |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getName () : string { |
|
94
|
|
|
return $this->getGraphPage()->getName(); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function getUsername () : string { |
|
98
|
|
|
return $this->getGraphNode()->getField("username"); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function countLikes () : int { |
|
102
|
|
|
return $this->getGraphPage()->getField("fan_count"); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getAbout () : string { |
|
106
|
|
|
return $this->getGraphNode()->getField("about"); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getWebsite () : string { |
|
110
|
|
|
return $this->getGraphNode()->getField("website"); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function getAllItems () : array { |
|
114
|
|
|
return $this->getGraphNode()->all(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
?> |
|
|
|
|
|
|
120
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.