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
| <?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once('src/Facebook/autoload.php' );
use Facebook\Facebook;
use Facebook\FacebookApp;
use Facebook\FacebookRequest;
class PageFeed{
const APP_ID = 'XXXX';
const APP_SECRET = 'XXXX';
const LONG_LIVE_TOKEN = 'XXXX';
const LONG_LIVE_TOKEN_FOOD = 'XXXX';
const LONG_LIVE_TOKEN_ATELIER = 'XXXX';
const PAGE_ID = 'XXXX';
const PAGE_ID_FOOD = 'XXXX';
const PAGE_ID_ATELIER = 'XXXX';
protected $data;
protected $facebook;
private $page;
private $access_token;
public function __construct($page){
if($page == 'demXXXX'){
$this->page = static::PAGE_ID;
$this->access_token = static::LONG_LIVE_TOKEN;
}elseif($page == 'demXXXX'){
$this->page = static::PAGE_ID_FOOD;
$this->access_token = static::LONG_LIVE_TOKEN_FOOD;
}elseif($page == 'demXXXX'){
$this->facebook->setAccessToken(static::LONG_LIVE_TOKEN_ATELIER);
$this->access_token = static::LONG_LIVE_TOKEN_ATELIER;
}
$this->facebook = new Facebook([
'app_id' => static::APP_ID,
'app_secret' => static::APP_SECRET,
'default_graph_version' => 'v2.7',
'default_access_token' => $this->access_token,
]);
}
public function request($method = 'GET', $params){
$request = $this->facebook->request($method, $params);
try {
$response = $this->facebook->getClient()->sendRequest($request);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphEdge()->asArray();
return $graphNode;
}
public function getPost($period){
$timestamp = strtotime($period);
$response = $this->facebook->get('/XXXX/posts?fields=reactions.limit(0).summary(true)&limit=30');
$getPostID = $response->getGraphEdge()->asArray();
echo '<pre>';
var_dump($getPostID);
echo '</pre>';
}
}
?> |
Partager