php - Twitter API and duplicate tweets -


i'm using twitter api via codebird php display tweets using ajax on site. i'm having trouble preventing duplicates after first call since max_id shows tweets after including max_id.

seems silly why they'd way, me, can't seem find else asking same question. though lot of people come across. leads me think i'm not doing correctly.

    // prepare args     $tw_args = array(         'count' => 5,         'trim_user' => true     );      // if havea last id, set     if (isset($last_id)) {         $tw_args['max_id'] = $last_id;     }      // new tweet arr     $tweets = array();      // raw tweets     $raw_tweets = (array) $cb->statuses_usertimeline($tw_args);      // loop through tweets     ($i = 0; $i < count($raw_tweets); $i++) {           // add id , text our new tweets array         $tmp = array(             'id' => $raw_tweets[$i]->id_str,             'text' => $raw_tweets[$i]->text         );          array_push($tweets, $tmp);     }       // return tweets array     return $tweets; 

how prevent twitter api returning tweet same id max_id?

if understood you're trying do, seems max_id tweet included in $raw_tweets array?

if so, add condition in loop not add tweet max_id id $tweets array :

    // ...      ($i = 0; $i < count($raw_tweets); $i++) {          // check if current tweet's id match max_id         if($raw_tweets[$i]->id_str == max_id)             continue;          // add id , text our new tweets array         $tmp = array(             'id' => $raw_tweets[$i]->id_str,             'text' => $raw_tweets[$i]->text         );          array_push($tweets, $tmp);     }      // ... 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -