Advertisement
darkoneko

Untitled

Oct 4th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @author Wolfgang ten Weges
  4.  * @desc script de suppression de tweets.
  5. */
  6. require('lib/tmhOAuth.php');
  7.  
  8. //if we flood the API, it'll throttle or block us, so be careful.
  9. define("TIME_BETWEEN_API_CALLS", 5);
  10.  
  11. $twitterAuth = array( //account parameters
  12.   'consumer_key' => 'xxxxxxxxxxxx',
  13.   'consumer_secret' => 'xxxxxxxxxxx',
  14.   'user_token' => 'xxxxxxx-xxxxxxxx',
  15.   'user_secret' => 'xxxxxxxxxxxxxx',
  16. );
  17.  
  18. $oa = new tmhOAuth( $twitterAuth );
  19. $re = fopen("tweets.csv", 'r'); //file gotten from https://twitter.com/settings/account
  20.  
  21. while( $ligne = fgetcsv($re) ) {
  22.    $id = $ligne[0];
  23.  
  24.    //skim throught the cvs file until we reach the desired point
  25.    //alternatively, you could use for($a=0 ; $a < NB ; $a++) { fgetcsv($re); } to skip the NB first tweets
  26.    if($id > xxxxxxxx) continue;
  27.  
  28.    $http_code = $oa->request(
  29.       'POST',
  30.       $oa->url("1.1/statuses/destroy/$id"),
  31.       array(
  32.          'id' => $id,
  33.          'include_entities' => 'false',
  34.          'trim_user' => 'true',
  35.       )
  36.    );
  37.  
  38.    //404 = not found ; 503 = service unavailable (temporaire/rare, donc passe au suivant plutot qu'arreter le script)
  39.    if ($http_code != 200) {
  40.       echo "\n[EE] error while deleting";
  41.       if( $http_code == '404' || $http_code == '503') {
  42.          echo "\n $http_code";
  43.          continue;
  44.       }
  45.       echo "\n\n";
  46.       print_r($oa->response['info']);
  47.       break;
  48.    }
  49.  
  50.    echo "\n$id ".$ligne[5];
  51.    sleep(TIME_BETWEEN_API_CALLS); //pause pour pas flood
  52. }
  53.  
  54. echo "\nfin\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement