繁体   English   中英

Twitter粉丝数量

[英]Twitter follower count number

获取纯文本中的关注者计数的唯一方法是使用cURL吗? 或者twitter API是否提供任何此类选项?

https://api.twitter.com/1/users/lookup.json?screen_name=tvdw (我的个人资料,只需替换屏幕名称)

也可以XML格式提供: https//api.twitter.com/1/users/lookup.xml?screen_name = tvw

在PHP中获取它:

$data = json_decode(file_get_contents('https://api.twitter.com/1/users/lookup.json?screen_name=tvdw'), true);
echo $data[0]['followers_count'];

在API 1.1版中,您可以使用: https//dev.twitter.com/docs/api/1.1/get/users/show

'followers_count'字段应包含跟随者计数。

在不推荐使用的API版本1中,您可以使用: https//dev.twitter.com/docs/api/1/get/users/show

Twitter API 1.0已弃用,不再有效。 使用REST 1.1 API,您需要oAuth身份验证才能从Twitter检索数据。

请改用:

<?php
    require_once('TwitterAPIExchange.php'); //get it from https://github.com/J7mbo/twitter-api-php

    /** Set access tokens here - see: https://dev.twitter.com/apps/ **/
    $settings = array(
        'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN",
        'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET",
        'consumer_key' => "YOUR_CONSUMER_KEY",
        'consumer_secret' => "YOUR_CONSUMER_SECRET"
    );

    $ta_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
    $getfield = '?screen_name=REPLACE_ME';
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $follow_count=$twitter->setGetfield($getfield)
    ->buildOauth($ta_url, $requestMethod)
    ->performRequest();
    $data = json_decode($follow_count, true);
    $followers_count=$data[0]['user']['followers_count'];
    echo $followers_count;
?>
<a href="https://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow @twitterapi</a>

<script>
!function(d,s,id){
    var js,fjs=d.getElementsByTagName(s)[0];
    if(!d.getElementById(id)){
        js=d.createElement(s);
        js.id=id;
        js.src="//platform.twitter.com/widgets.js";
        fjs.parentNode.insertBefore(js,fjs);
    }
}
(document,"script","twitter-wjs");    
</script>

data-show-count = "true"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM