|
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: JuKuCMS |
|
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
|
|
|
|
|
34
|
|
|
class Page { |
|
35
|
|
|
|
|
36
|
|
|
protected $fb = null; |
|
37
|
|
|
protected $api = null; |
|
38
|
|
|
|
|
39
|
|
|
protected $pageID = ""; |
|
40
|
|
|
protected $response = null; |
|
41
|
|
|
protected $graphNode = null; |
|
42
|
|
|
|
|
43
|
|
|
public function __construct (Facebook $fb, FacebookApi $api) { |
|
44
|
|
|
$this->fb = $fb; |
|
45
|
|
|
$this->api = $api; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function loadPage (string $name) { |
|
49
|
|
|
$this->pageID = $name; |
|
50
|
|
|
|
|
51
|
|
|
//https://stackoverflow.com/questions/7633234/get-public-page-statuses-using-facebook-graph-api-without-access-token |
|
52
|
|
|
|
|
53
|
|
|
//get all available fields: /{page-id}?metadata=1 |
|
54
|
|
|
|
|
55
|
|
|
try { |
|
56
|
|
|
// Returns a `Facebook\FacebookResponse` object |
|
57
|
|
|
$this->response = $this->fb->get( |
|
58
|
|
|
"/" . $this->pageID . "?fields=id,about,fan_count,website,location,name,username,phone,feed", |
|
59
|
|
|
$this->api->getAccessToken() |
|
60
|
|
|
); |
|
61
|
|
|
} catch(FacebookResponseException $e) { |
|
62
|
|
|
echo 'Graph returned an error: ' . $e->getMessage(); |
|
63
|
|
|
exit; |
|
|
|
|
|
|
64
|
|
|
} catch(FacebookSDKException $e) { |
|
65
|
|
|
echo 'Facebook SDK returned an error: ' . $e->getMessage(); |
|
66
|
|
|
exit; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$this->graphNode = $this->response->getGraphNode(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
?> |
|
|
|
|
|
|
75
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.