Twitter API 1.0 bị phản đối và không còn hoạt động. Với REST 1.1 API, 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;
?>
Phân tích XML có thể được dễ dàng hơn trong một số trường hợp.
Dưới đây là một giải pháp (thử nghiệm):
<?php
$xml = new SimpleXMLElement(urlencode(strip_tags('https://twitter.com/users/google.xml')), null, true);
echo "Follower count: ".$xml->followers_count;
?>
Hope this helps!
Nguồn
2013-07-01 16:28:07
Bạn cần phải sử dụng một kết nối oauth bây giờ với v1.1 – Novocaine
Và làm thế nào Tôi có thể sử dụng nó không? – Enve