Seperate single tweets into an individual collection. Combine threaded Tweets / Tweet replies into combined collection.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Seperate single tweets into an individual collection. | |
* Combine threaded Tweets / Tweet replies into combined collection. | |
*/ | |
function get_tweets($data) | |
{ | |
if ($data === false) { | |
return 'Cannot view tweets'; | |
} | |
//array contaning tweet data | |
$tweets = []; | |
//replied tweet id | |
$rid = null; | |
//index increment to group tweets | |
$idx = 1; | |
//loop over tweets | |
foreach ($data as $key => $tw) { | |
//Successive tweets in thread | |
if (!is_null($tw->in_reply_to_status_id) && is_null($rid)) { | |
$tweets[$idx][$tw->id] = $tw->full_text; | |
continue; | |
} | |
//First tweet in thread | |
if (is_null($tw->in_reply_to_status_id) && is_null($rid)) { | |
$tweets[$idx][$tw->id] = $tw->full_text; | |
} | |
//Store replied tweet id | |
$rid = $tw->in_reply_to_status_id; | |
//Index increment to group tweets | |
$idx++; | |
} | |
//return tweets | |
return $tweets; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment