如何从推特上获得关注人数

How to get followers count from twitter

本文关键字:      更新时间:2023-09-26

我想从twitter站点获得关注者数量,我已经使用了这个查询,它运行得很好,但现在没有运行,因为twitter API现在已经更改了。我在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>

由于twitter个人资料上的任何人都可以访问关注者数量,因此可以使用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;
});

twitter API 1.1发生了很多变化,首先,您不能直接调用来获取数据。您需要进行某种身份验证才能进行这些呼叫。

请阅读本文档,其中说明了身份验证的必要性。您可以根据需要进行Oauth身份验证或仅应用程序身份验证。

完成身份验证后,您可以使用此api 获得追随者列表

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

阅读此处了解更多信息和完整的参数集

相关文章:
  • 没有找到相关文章