fdsaresolution
fdsaresolution

Reputation: 17

How to display tweets posted an hour ago from multiple users (PHP implementation)

long story short .. I'm using twitter API to retrieve tweets and analyse them sentimentally. Now I want to fetch tweets about a keyword posted an hour ago. How to implement this with PHP? The current version looks like this:

$contents = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=".$keyw."&locate=en&rpp=100");

I suppose if lucky the easiest solution might be adding another search query, something like tweets.json?q=".$keyw."&locate=en&rpp=100&time=3600" but not sure. Didn't find any instruction elsewhere.

So the data is retrieved as json and if use print_r($contents); it will generate PHP array i think. Then there's something like

[created_at] => Mon Nov 30 17:41:31 +0000 2009

Maybe I can make use of this? Thank you for helping. :)

Upvotes: 0

Views: 66

Answers (1)

Answers_Seeker
Answers_Seeker

Reputation: 468

Here is the logic advised using the DateTime and DateInterval filtering:

$tweets_recieved = array (/* the tweets you recieved */);
function callback ($tweet)
{
    $curr_date = new DateTime();

    if ($tweet['created_at']->add(new DateInterval("PT1H")) < $curr_date)
        unset($tweet);
}
// Res contains the tweets from less than an hour ago
$res = array_map('callback', $tweets_recieved);

Upvotes: 1

Related Questions