Skip to content

Commit

Permalink
Merge branch 'richard67-facebook-api-v2.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
compeak committed Nov 20, 2017
2 parents 92f2687 + fb5386d commit 3d8b066
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/Backend/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function setConfig(array $config)
public function getRequest($url)
{
$accessToken = urlencode($this->config['app_id']) .'|'.urlencode($this->config['secret']);
$query = 'https://graph.facebook.com/v2.8/?id='.urlencode($url).'&access_token='.$accessToken;
$query = 'https://graph.facebook.com/v2.10/?id='.urlencode($url) . '&fields=engagement&access_token='
. $accessToken;

return new \GuzzleHttp\Psr7\Request('GET', $query);
}
Expand All @@ -42,11 +43,14 @@ public function getRequest($url)
*/
public function extractCount(array $data)
{
if (isset($data['data']) && isset($data['data'][0]) && isset($data['data'][0]['total_count'])) {
return $data['data'][0]['total_count'];
}
if (isset($data['share']) && isset($data['share']['share_count'])) {
return $data['share']['share_count'];
if (isset(
$data['engagement']['reaction_count'],
$data['engagement']['comment_count'],
$data['engagement']['share_count']
)) {
return $data['engagement']['reaction_count']
+ $data['engagement']['comment_count']
+ $data['engagement']['share_count'];
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions tests/FacebookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function testUsesGraphApi()
$request = $facebook->getRequest('http://www.heise.de');

$this->assertEquals('graph.facebook.com', $request->getUri()->getHost());
$this->assertEquals('/v2.8/', $request->getUri()->getPath());
$this->assertEquals('/v2.10/', $request->getUri()->getPath());
$this->assertEquals(
'id='.urlencode('http://www.heise.de').'&access_token=foo%7Cbar',
'id='.urlencode('http://www.heise.de').'&fields=engagement&access_token=foo%7Cbar',
$request->getUri()->getQuery()
);
}
Expand Down

0 comments on commit 3d8b066

Please sign in to comment.