Advertisement
Guest User

Twitter RT bot

a guest
Jun 4th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.79 KB | None | 0 0
  1. <?PHP                                                                                                                                                        
  2.  
  3. # https://github.com/abraham/twitteroauth                                                                                                                                                              
  4. include "lib/twitteroauth/twitteroauth/twitteroauth.php";                                                                                                    
  5.                                                                                                                                                              
  6. # connect to twitter                                                                                                                                          
  7. $connection = new TwitterOAuth(                                                                                                                              
  8.   "...", #$consumer_key,                                                                                                                    
  9.  "...", #$consumer_secret,                                                                                          
  10.  "...", #$oauth_token,                                                                                          
  11.  "..." # $oauth_token_secret                                                                                                                                                                                                                                                      
  12. );                                                                                                                                                            
  13.                                                                                                                                                              
  14. # get id of last retweeted by us                                                                                                                              
  15. # we just want to retweet newer tweets                                                                                                                        
  16. $response = $connection->get( 'statuses/retweeted_by_me');                                                                                                    
  17.                                                                                                                                                              
  18. if ($response[0] )                                                                                                                                            
  19. {                                                                                                                                                            
  20.   $lastId = $response[0]->retweeted_status->id;                                                                                                              
  21. }                                                                                                                                                            
  22.                                                                                                                                                              
  23. if (!$lastId) {                                                                                                                                              
  24.   exit();                                                                                                                                                    
  25. }                                                                                              
  26. print "Last retweeted ID: " . $lastId . "\n";                                                                                                                
  27.                                                                                                                                                              
  28. print "Retweeting the following tweets:\n\n";                                                                                                                
  29.                                                                                                                                                              
  30. # now get the tweets we want to retweet                                                                                                                      
  31. $response = $connection->get(                                                                                                                                
  32.   'search',                                                                                                                                                  
  33.   array(                                                                                                                                                      
  34.     'q'=> '#bge OR grundeinkommen',                                                                                                                          
  35.     'result_type' => 'recent',                                                                                                                                
  36.     'rpp' => 100                                                                                                                                              
  37.   )                                                                                                                                                          
  38. );                                                                                                                                                            
  39.                                                                                                                                                              
  40. foreach ( array_reverse( $response->results ) as $tweet ) # reverse results, to retweet oldest first                                                          
  41. {                                                                                                                                                            
  42.   # only retweet newer tweets                                                                                                                                
  43.  if (                                                                                                                                                        
  44.     ( $tweet->id > $lastId ) &&                 # newer than our last RT                                                                                      
  45.    ( $tweet->from_user_id != 212910781 ) &&    # no RT if BGEbot alread did                                                                                  
  46.    ( substr($tweet->text, 0, 3 ) != 'RT ' ) &&   # no pure text retweets from others                                                                        
  47.    ( $tweet->iso_language_code == 'de' ) &&      # only tweets in German                                                                                    
  48.    1                                                                                                                                                        
  49.   ){                                                                                                                                                          
  50.                                                                                                                                                              
  51.     print $tweet->id."\t";                                                                                                                                    
  52.     print $tweet->text . "\n";                                                                                                                                
  53.     $connection->post( 'statuses/retweet/' . $tweet->id );                                                                                                    
  54.     #print_r($tweet);                                                                                                                                        
  55.  }                                                                                                                                                          
  56. }                                                                                                                                                            
  57. #print_r($connection);                                                                                                                                        
  58. print "Done.\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement