heiseonline / shariff-backend-php

👮 PHP backend for Shariff. Shariff enables website users to share their favorite content without compromising their privacy.
http://ct.de/-2467514
133 stars 44 forks source link

Facebook-count is zero, but facebook debugger returns 30 #127

Closed ahoiroman closed 6 years ago

ahoiroman commented 6 years ago

Hi there,

am using the backend for quite a while now.

But unfortunately the facebook-count always shows 0.

This is my config:

array(4) {
  ["cache"]=>
  array(2) {
    ["ttl"]=>
    int(5)
    ["cacheDir"]=>
    string(38) "/var/www/domain.org/tmp/cache"
  }
  ["domains"]=>
  array(1) {
    [0]=>
    string(22) "domain.org"
  }
  ["services"]=>
  array(2) {
    [0]=>
    string(8) "Facebook"
    [1]=>
    string(10) "GooglePlus"
  }
  ["Facebook"]=>
  array(2) {
    ["app_id"]=>
    string(15) "my-id"
    ["secret"]=>
    string(32) "my-secret"
  }
}

This is the result: {"facebook":0,"googleplus":0}

But it should be 30?

ahoiroman commented 6 years ago

Problem can be solved by changing:

heise/shariff/src/Backend/Facebook.php

Replace in function getRequest

$query = 'https://graph.facebook.com/v2.8/?id='.urlencode($url).'&access_token='.$accessToken;

with

$query = 'https://graph.facebook.com/v2.10/?id='.urlencode($url).'&fields=og_object{engagement}&access_token='.$accessToken;

And in function extractCount

Add

if (isset($data['og_object']['engagement']['count'])) {

return $data['og_object']['engagement']['count'];
}
return 0;
}
liayn commented 6 years ago

This seems to be an issue with the settings of your facebook user. AFAIK you can set the minimum API version per user. I suppose your's is 2.10 The current code works flawlessly for us on various live sites

ahoiroman commented 6 years ago

If you create a new Facebook App, you can not set an API-version < 2.10 .

So the current code does only work if you created your app a while ago.

liayn commented 6 years ago

Alright. Thanks for figuring that out. Time to update the code then. Can you please push your suggested change as a pull request to speed up things?

richard67 commented 6 years ago

Pull request see https://github.com/heiseonline/shariff-backend-php/pull/128. Please test.

ahoiroman commented 6 years ago

Works for me :)

ahoiroman commented 6 years ago

Any idea, when this will be merged? My users (I created a little extension for Pagekit CMS) are waiting for this :)

richard67 commented 6 years ago

@SPQRInc Maybe ask here: https://github.com/heiseonline/shariff-backend-php/pull/128.

ahoiroman commented 6 years ago

Great, it has been merged :)

Now I'm just waiting for a release of version 7.1, which includes the bugfix :)

richard67 commented 6 years ago

@SPQRInc No need to wait, 7.0.1 is out.

compeak commented 6 years ago

This should be fixed in 7.0.1.