Twitter粉丝数量

use*_*313 11 php twitter curl

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

Tom*_*rdt 9

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'];
Run Code Online (Sandbox Code Playgroud)

  • API v1.0不再有效.此解决方案不再有效. (11认同)
  • API v1已过时,不再起作用. (4认同)

myy*_*yyk 8

在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


小智 7

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;
?>
Run Code Online (Sandbox Code Playgroud)