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

Update Facebook service to latest Facebook Graph API version v18.0 and change field from engagement to og_object #186

Closed richard67 closed 10 months ago

richard67 commented 2 years ago

Current Facebook Graph API version v18.0 has been released on September 12, 2023, see https://developers.facebook.com/docs/graph-api/changelog.

According to the changelog, there have not been any breaking changes regarding sharing counts, see https://developers.facebook.com/docs/graph-api/changelog/version18.0, so theoretically only the version number would have to be increased with this PR here.

But there is something which has been noted in the release notes of version v10.0 which has an impact on getting the share counters, see section "URL" https://developers.facebook.com/docs/graph-api/changelog/version10.0 :

URL

Applies to v10.0+. Will apply to all versions on May 25, 2021.

Engagement
- Due to privacy concerns, counts returned by a "GET /?id={url}/engagement" request may not match raw counts. 
- Requests for the "GET /?id={url}/engagement" field for the same URL will be limited to 10 requests per hour.

The first point seems to be the reason that the counters in the answer are all zero when using the existing code with just the version number changed, like I have done it many times with PR, the last one is #169 .

But if I change fields=engagement to fields=og_object{engagement} (or to be precise, fields=og_object%7Bengagement%7D with the curly brasckets encoded), then it works, and the response looks like:

{
   "og_object": {
      "engagement": {
         "count": 43,
         "social_sentence": "43 people like this."
      },
      "id": "132647790271874"
   },
   "id": "http://www.richard-fath.de/de/music/recordings/htlv-iii.html"
}

The count is the total of the 3 counts which are received with the current code without this PR.

This PR here makes the necessary changes to work that way. I also works with previous API versions in that way.

digitalgopnik commented 10 months ago

@richard67 Thanks for you work! Will be merged :+1: