最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get followers count from twitter - Stack Overflow

programmeradmin1浏览0评论

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(".json?callback=?",

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

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./users/Obama.json?callback=?",

    function (data) {
        document.getElementById("spnTwitterFolowersCount").innerHTML = data.followers_count;
        //alert('Obama has ' + data.followers_count + ' Followers');
    });
</script>
Share Improve this question edited Aug 30, 2013 at 10:10 Arturs 1,2545 gold badges21 silver badges28 bronze badges asked Aug 30, 2013 at 6:52 kabijoykabijoy 3031 gold badge4 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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./v1/public/yql?q=select%20content%20from%20html%20where%20url%3D%22https%3A%2F%2Ftwitter.%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;
});

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./1.1/followers/ids.json?cursor=-1&screen_name=sitestreams&count=5000

Read here for more information and plete set of parameters

发布评论

评论列表(0)

  1. 暂无评论