Advertisement
Guest User

Untitled

a guest
May 13th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. require_once("twitter/twitteroauth/twitteroauth.php");
  5.  
  6. $username="root";
  7. $password = "root";
  8. $database="xx";
  9. mysql_connect('localhost',$username,$password);
  10. $db_selected = mysql_select_db($database);
  11.  
  12. if ( !$db_selected ) {
  13. die( "Unable to select database");
  14. }
  15. $queryy = "SELECT * FROM 'twitter'";
  16. $resultt = mysql_query($queryy);
  17.  
  18. while ($row = mysql_fetch_object($resultt)) {
  19. $accesstoken=$row['twit_email'];
  20. $accesstokensecret=$row['password'];
  21.  
  22. }
  23. $cursor = -1;
  24. $followers = array();
  25.  
  26. do {
  27. $json = file_get_contents('https://api.twitter.com/1.1/search/tweets.json?cursor=' . $cursor);
  28. $accounts = json_decode($json);
  29. foreach ($accounts->users as $account)
  30. $followers[$account->id_str] = $account->screen_name;
  31.  
  32. $cursor = $accounts->next_cursor;
  33.  
  34. } while ($cursor > 0);
  35.  
  36. // Now save in the database
  37. foreach($followers as $key => $value) {
  38.  
  39. // Do we update or do we insert?
  40. $res = $this-> $database->prepare('SELECT COUNT(*) FROM `twit_contacts` WHERE twitID = :id');
  41. $res->execute(array('id' => $key));
  42. $rows = $res->fetch(PDO::FETCH_NUM);
  43.  
  44. if (!$rows[0])
  45. $this->$database->prepare('INSERT INTO `twit_contacts` SET twitID = :id, contactName = :name, dateContactFrom = NOW()')
  46. ->execute(array(':id' => $key, ':name' => $value));
  47. else
  48. $this->$database->prepare('UPDATE `twit_contacts` SET contactName = :name, dateContactFrom = NOW() WHERE twitID = :id')
  49. ->execute(array(':id' => $key, ':name' => $value));
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. $query = "SELECT * FROM 'twit_contacts'";
  61. $result = mysql_query($query);
  62.  
  63. $oldFollowers = array();
  64.  
  65. while ($row = mysql_fetch_object($result)) {
  66. $oldFollowers[$row->contactID] = array('screen_name'=>$row->screen_name, 'contactName'=>$row->username);
  67. echo $oldFollowers['screen_name'];
  68. }
  69.  
  70.  
  71. mysql_close();
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement