2011-12-30 117 views

回答

8

https://api.twitter.com/1/users/lookup.json?screen_name=tvdw(我的個人資料,只需更換網名)

也可作爲XML:https://api.twitter.com/1/users/lookup.xml?screen_name=tvdw

獲取在PHP:

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

謝謝,我會標示出它接受什麼時候會允許我。 – user1117313 2011-12-30 19:33:31

+0

我認爲最後一行現在應該是'echo $ data [0] ['followers_count'];' – Eli 2012-03-29 15:32:30

+11

API v1.0不再有效。此解決方案不再有效。 – 2013-06-14 00:31:48

-2
<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"

7

微博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; 
?>