Cách duy nhất để có được số lượng người theo dõi trong văn bản thuần túy đang sử dụng cURL? hoặc API twitter cung cấp bất kỳ tùy chọn nào như vậy?Số người theo dõi Twitter
Trả lời
https://api.twitter.com/1/users/lookup.json?screen_name=tvdw (hồ sơ của tôi, chỉ cần thay thế tên màn hình)
Cũng có sẵn như XML: https://api.twitter.com/1/users/lookup.xml?screen_name=tvdw
Lấy nó trong PHP:
$data = json_decode(file_get_contents('https://api.twitter.com/1/users/lookup.json?screen_name=tvdw'), true);
echo $data[0]['followers_count'];
Trong phiên bản API 1.1 bạn có thể sử dụng: https://dev.twitter.com/docs/api/1.1/get/users/show
trường 'followers_count' phải chứa số lượng người theo dõi.
Trong phiên bản API 1 mà bị phản đối, bạn có thể sử dụng: https://dev.twitter.com/docs/api/1/get/users/show
không hoạt động url ... – David
<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"
Twitter API 1.0 bị phản đối và không còn hoạt động. Với API REST 1.1, bạn cần xác thực oAuth để truy xuất dữ liệu từ Twitter.
Sử dụng này để thay thế:
<?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;
?>
Cảm ơn, tôi sẽ đánh dấu nó được chấp nhận khi nó sẽ cho phép tôi. – user1117313
Tôi tin rằng dòng cuối cùng sẽ là 'echo $ data [0] [' followers_count '];' – Eli
API v1.0 không còn hoạt động. Giải pháp này không còn giá trị. –