Bonjour ,

J'essaye de récupérer des infos ( reactions , commentaire , partages ) sur des post facebook , le problème que j'ai est qu'il me retourne 0 commentaires et 0 reactions pour chaque post que j'interroge , quand je test sur le open graph api de facebook tout marche bien il me retourne les bons résultats ,j 'ai testé avec le meme access token et j'utilise le sdk 5-0-0 de Facebook ( la dernière version )
et voici mon code


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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>';
 
 
	}
 
}
 
 
?>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
<?php 
 
	require_once('class/PageFeed');
 
 
	$curent_date = date('y-m-D');
 
	$pageFeed = new PageFeed('XXXX');
 
	$pageFeed->getPost($curent_date);
 
 
?>
Et le resultat

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
array(30) {
  [0]=>
  array(2) {
    ["id"]=>
    string(30) "2526133XXX_10154315535XXX"
    ["reactions"]=>
    array(0) {
    }
  }
  [1]=>
  array(2) {
    ["id"]=>
    string(30) "2526XXXX_101543154524XXXX"
    ["reactions"]=>
    array(0) {
    }
  }
  [2]=>
  array(2) {
    ["id"]=>
    string(30) "2526133XXXX_1015431454149XXXX"
    ["reactions"]=>
    array(0) {
    }
  }
  [3]=>
  array(2) {
    ["id"]=>
    string(30) "2526133XXX_1015431435103XXX"
    ["reactions"]=>
    array(0) {
    }
  }
  [4]=>
  array(2) {
    ["id"]=>
    string(30) "25261330XXXX_1015431433515XXXX"
    ["reactions"]=>
    array(0) {
    }
  }