Count Tweets - Twitter API

时间:2017-09-05 11:45:39

标签: php json api twitter twitter-oauth

我想要计算从Twitter API脚本下面返回的所有推文。我无法找到如何计算在数组json中返回的推文..

代码:

<?php
ini_set('display_errors', 1);
require_once('TwitterAPIClass/TwitterAPIExchange.php');

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


/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/

// Twitter Search API goes back to max last 7 days
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%24neos&count=100&since=2017-09-4';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$twitter_data = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(), true);

print_r ($twitter_data);


$countTweets = count($twitter_data['statuses']);
echo $countTweets;           




?>

0 个答案:

没有答案