I'm trying to build a 'Follow' button with a vertical followers count above it. I had a solution working until Twitter retired the 1.0 API today and now require an Oauth solution. My question, what is the best, easiest solution for this (preferably JS).
Here is the old solution
$.getJSON("https://api.twitter.com/1/users/show.json?callback=?&screen_name=twitter",
function(data) {
$('.here').text(data);
});
And the error I'm getting now
GET https://api.twitter.com/1/users/show.json?callback=jQuery20205200183007400483_1371012819892&screen_name=twitter&_=1371012819893 410 (Gone)
Since Twitter stopped providing an API that doesn't require authentication for simple read-only operations like getting the follower count, they deserve to be scrapped.
We'll use YQL to get the Twitter page of the user, then parse out the follower count. This also works on the client alone, without same-origin restrictions:
Of course, this is somewhat brittle and depends on Twitter keeping the same markup - a hidden
input
element after the closing</html>
.Firstly, according to official sources:
There isn't any easy way to perform client side requests to the new 1.1 API via AJAX. You should use some server-side language to perform this transaction, like php.
You're getting
410 (Gone)
response code from their API. Let's see what this actually means:Now let's take a look at the latest twitter API news:
As of yesterday, (June 11th 2013), the previously deprecated v1.0 API was retired. This means that the resource will not be available again, and you need to progress onto the v1.1 API.
The v1.1 API requires authenticated requests, usually using OAuth or 'application-specific'.
Not sure why, but you already posted the most helpful answer as a comment, but yes that's a simple library I wrote to help you guys out transitioning to v1.1 of the twitter API.
Your response:
GET https://api.twitter.com
/1/
[Emphasis my own]
contains the API version in the URL.In closing, any twitter url's with /1/ instead of /1.1/ will no longer take on any requests whatsoever, and you will always get a
410 (Gone)
response. Time to move to 1.1!i follow this step.and to get twitter follower count
use this code
you can change the "screen_name" and get the follower count.
cheers.