Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST API is gone, facebook share count is not working now #294

Open
Coyoter opened this issue Aug 19, 2016 · 21 comments
Open

REST API is gone, facebook share count is not working now #294

Coyoter opened this issue Aug 19, 2016 · 21 comments

Comments

@Coyoter
Copy link

Coyoter commented Aug 19, 2016

Aug 18, the FB REST API is gone.

There are any solution to fix my share count?

@neotropic2023
Copy link

Can confirm also, Facebook numbers are all zero now. Even in their demos.

@tarqd
Copy link

tarqd commented Aug 20, 2016

Could be solved by using graph.facebook.com/{url} instead of FQL

@sphism
Copy link
Contributor

sphism commented Aug 21, 2016

Same for us, I'll try the graph api mentioned above

@sphism
Copy link
Contributor

sphism commented Aug 22, 2016

Got the fb share counts working again... two bits of code need altering: Weirdly you have to switch back to a previous version of the facebook api (no idea why)

/* Json URL to get count number
  ================================================== */
  urlJson = {
    googlePlus: "",

    //new FQL method by Sire
    //facebook: "https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?",
    //old method
    facebook: "http://graph.facebook.com/?id={url}&callback=?",
    //facebook : "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls={url}&format=json"

Then the returned format is different so you have to change that too:

//get the FB total count (shares, likes and more)
        //else if(json.data && json.data.length > 0 && typeof json.data[0].total_count !== "undefined"){ //Facebook total count
        //  count += parseInt(json.data[0].total_count, 10);
        //}

        // Hacked: matt: FB api no longer returns share count, switching api's
        // returns data in this format now.
        else if(json.share && json.share && typeof json.share.share_count !== "undefined"){ //Facebook total count
          count += parseInt(json.share.share_count, 10);
        }
        // End hacked: matt

@ablunier
Copy link

Same problem here and your hack worked for me @sphism. Thank you!

njt1982 added a commit to njt1982/Sharrre that referenced this issue Aug 22, 2016
@njt1982
Copy link

njt1982 commented Aug 22, 2016

See Pull Request #296 - I've implemented @sphism 's changes... with a minor tweak - should be on HTTPS.

@martinfritch
Copy link

martinfritch commented Aug 22, 2016

I implemented the hack from @sphism and my counts are still not working. GitHub is saying the code was last updated March 3. I seem to be missing something.

I found this article published last week: http://www.inc.com/james-parsons/the-era-of-the-share-count-is-coming-to-an-end.html that says FB Shared counts are no longer available...

@sphism
Copy link
Contributor

sphism commented Aug 22, 2016

@martinfritch Have a play with the facebook graph explorer, that's how i figured out how to get ours working yesterday. https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=%3Fid%3Dhttp%253A%252F%252Fwww.imdb.com%252Ftitle%252Ftt2015381%252F&version=v2.7

Also try the code from the pull request @njt1982 made: #296

@njt1982
Copy link

njt1982 commented Aug 22, 2016

@martinfritch did you use http or https for the graph facebook URL? http did not work on our project as the project is hosted on https. Chrome blocked the request.

That graph URL does (currently) work, but I have no idea if/when it'll be retired. It might just be that the person that wrote the blog didn't look around for new URLs..

This definitely works:
https://graph.facebook.com/?id=https://github.com/&callback=test

@Ewster
Copy link

Ewster commented Aug 23, 2016

Glad to find this fix. Thanks @sphism this worked for me.

@aandrewjoyce
Copy link

@sphism 's fix didn't work for me -- we're still getting 0s everywhere. Anyone know of any alternatives to sharrre that can accomplish the same thing?

@martinfritch
Copy link

Just an update: I got @sphism 's fix to work. Not sure what exactly I did, or what changed, but after working on it for several hours and trying different variations, I got a valid response back and now the counts are working fine!

@njt1982
Copy link

njt1982 commented Aug 23, 2016

@martinfritch do you use any kind of version control so you can get a diff to see what you changed?

@aandrewjoyce did you change it from http to https? Do you get any errors in the console or network tab?

This patch does work, so if it doesn't work for you it would be good to know why.

@sphism
Copy link
Contributor

sphism commented Aug 23, 2016

@martinfritch glad you got it sorted.

@aandrewjoyce Not sure what to say. Have you tried using the graph api explorer https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=%3Fid%3Dhttp%253A%252F%252Fwww.imdb.com%252Ftitle%252Ftt2015381%252F&version=v2.7

I made sure i was getting results in there first, then figured out how to get it working on our site.

There are loads of different version of the api, I wonder if the one you are using returns the data in a slightly different format???? If you look in the jquery.sharrre.js file for the Plugin.prototype.getSocialJson method, you can uncomment this line

//console.log(json); //debug

Then you see all the returned JSON from each of the social sites. The facebook fql api used to return the share count as:

json.data[0].total_count

The graph api i just switched to returns it as:

json.share.share_count

It might be that the version of the api you are connecting to returns it slightly differently??? I'm not sure, I don't know much about the different fb api's.

If you use that graph api explorer i liked to above then you might be able to figure it out

@martinfritch
Copy link

The code I'm using is exactly what @sphism posted. However, the query isn't working again this morning. I'm getting the following response back from FB:

   "error": {
      "message": "(#4) Application request limit reached",
      "type": "OAuthException",
      "is_transient": true,
      "code": 4,
      "fbtrace_id": "DzW6CEr+WDZ"
   }

I bet this is why my first attempt appeared to be not working.

@njt1982
Copy link

njt1982 commented Aug 24, 2016

ahhh interesting! Never considered that Facebook would implement API limits...

@Coyoter
Copy link
Author

Coyoter commented Aug 24, 2016

�Check my website's share counter, it's working now:

http://www.hungry.tw/2016/08/ShanHaiGo.html

How I fixed that :

First Step. Change the "Json url to get count number" in your sharer.js, ex

/* Json URL to get count number
================================================== */
urlJson = {
googlePlus: "",
facebook: "https://graph.facebook.com/v2.7/?access_token=PUTYOURTOKENHERE&id={url}&callback=?",
//facebook : "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls={url}&format=json"

Second Step. Add one line code at : //console.log('name : ' + name + ' - url : '+url); //debug

ex.

} else if (typeof json[0] !== "undefined") { //Stumbleupon
} else if (typeof json.share !== "undefined") {
count += parseInt(json.share.share_count, 10);

you can use cmd(ctrl)+(F) to find "//Stumbleupon", and you will find that.

the counter works fine now!!! of course, you need an Facebook app token first.

You can find your token here if you already have an Facebook app:

https://developers.facebook.com/tools/accesstoken/

Enjoy your counter now : )

warning: An app token have limit of request. I suggest every people using the personal token for themself, and do not using other people's token. It's easy to reach the limit.

To create a Facebook app is easy and free. You do not need any Code skill.

Yu-Ci

@MeDroogie
Copy link

I'm confused... doesn't the USER token have a time limit (2 mos) while the APP token does not? And I'm guessing the app token should not be used here because it's client side, per the facebook documentation?

@Coyoter
Copy link
Author

Coyoter commented Aug 27, 2016

All token have limit, and you can check my.site its works.

@Patabugen
Copy link

Thanks @nikksan!

(there's a bug in your Markdown by the way - your link is not clickable)

https://fragrances.bg/blog/wp-content/themes/hueman/js/jquery.sharrre.min.js?ver=4.2.2

@AlxMedia
Copy link

AlxMedia commented Nov 1, 2016

@nikksan your fix sets 41 facebook likes to all posts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

13 participants