kabijoy
kabijoy

Reputation: 303

How to get followers count from twitter

I want the followers count from twitter site , Already I used this query, its worked well, but its not worked now,because the twitter API was changed now.i used script for getting count in a span id ="spnTwitterFolowersCount".

<script>
    $.getJSON("https://twitter.com/users/Obama.json?callback=?",

    function (data) {
        document.getElementById("spnTwitterFolowersCount").innerHTML = data.followers_count;
        //alert('Obama has ' + data.followers_count + ' Followers');
    });
</script>

Upvotes: 3

Views: 5513

Answers (2)

Sebastien Horin
Sebastien Horin

Reputation: 11067

As the followers count is accessible from anybody on a twitter profile you can use YQL:

var ttid = "twitterUsername";
var response = $.getJSON("https://query.yahooapis.com/v1/public/yql?q=select%20content%20from%20html%20where%20url%3D%22https%3A%2F%2Ftwitter.com%2F"+ttid+"%22%20and%20xpath%3D'%2F%2Fli%5Bcontains(%40class%2C%22ProfileNav-item--followers%22)%5D%2Fa%2Fspan%5Bcontains(%40class%2C%22ProfileNav-value%22)%5D'&format=json&callback=");
return response.success(function (followers) {
    return followers;
});

Upvotes: 3

Mandeep Jain
Mandeep Jain

Reputation: 2664

A lot has changed with the twitter API 1.1, for first, you cannot makes call directly to get data. You need to have some sort of authentication for making those calls.

Please read this documentation which states the need for authentication. You can have Oauth authentication or app-only authtentication based on your needs.

After you are done with the authentication, you can get the list of followers using this api

https://api.twitter.com/1.1/followers/ids.json?cursor=-1&screen_name=sitestreams&count=5000

Read here for more information and complete set of parameters

Upvotes: 1

Related Questions