Twitter Follow Script Modified


/ Published in: PHP
Save to your folder(s)

Modified version of the script created by Dave Stevens, Enables the user to input their credentials on a webpage rather than having to change the actual php script code.

Changes: Changed $user,$pass,$term

This is a modified script, the original can be found here: http://snipplr.com/view/17595/twitter-autofollow-php-script/


Copy this code and paste it in your HTML
  1. <html>
  2. <head>
  3. <title>Twitter Follow Script - Jonathon Maguire</title>
  4. </head>
  5. <body>
  6. <center>
  7. <u><h1><i>Twitter Follow Script</i></h1></u>
  8. <style>
  9. div {
  10. border: .2em dotted #900;
  11. }
  12. #border {
  13. border-width: .2em;
  14. border-style: solid;
  15. border-color: red;
  16. }
  17. </style>
  18. <form method="post" action="">
  19. <div id="border">
  20. <p><u>Username:</u></p>
  21. <input type="text" name="username" value="">
  22. <br><p><u>Password:</u></p>
  23. <input type="password" name="password" value="">
  24. <br><p><u>Search Term</u></p>
  25. <input type="text" name="term" value=""><br>
  26. <input type="submit" name="submit" value="submit">
  27. </div>
  28. </center>
  29.  
  30. </body>
  31. </html>
  32. <?php
  33.  
  34. // Twitter Auto-follow Script by Dave Stevens - http://davestevens.co.uk, Modified by Jonathon Maguire, http://www.unknowntruth.net
  35.  
  36. if(isset($_POST['submit']))
  37. {
  38. // Set the twitter user
  39. $user = $_POST['username'];
  40. $pass = $_POST['password'];
  41.  
  42. // Set the term you want to follow (e.g. "soccer")
  43. $term = $_POST['term'];
  44.  
  45. // Get already followed
  46. $userApiUrl = "http://twitter.com/statuses/friends.json";
  47.  
  48. if(isset($_POST['submit']))
  49. $ch = curl_init($userApiUrl);
  50. curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  52.  
  53. $apiresponse = curl_exec($ch);
  54.  
  55.  
  56. $followed = array();
  57.  
  58. if ($apiresponse) {
  59. $json = json_decode($apiresponse);
  60. if ($json != null) {
  61. foreach ($json as $u) {
  62. $followed[] = $u->name;
  63. }
  64. }
  65. }
  66.  
  67. $userApiUrl = "http://search.twitter.com/search.json?q=" . $term . "&rpp=100";
  68.  
  69. $ch = curl_init($userApiUrl);
  70. curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
  71. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  72.  
  73. $apiresponse = curl_exec($ch);
  74.  
  75.  
  76. if ($apiresponse) {
  77. $results = json_decode($apiresponse);
  78. $count = 90;
  79.  
  80. if ($results != null) {
  81.  
  82. $resultsArr = $results->results;
  83.  
  84. if (is_array($resultsArr)) {
  85.  
  86. foreach ($resultsArr as $result) {
  87.  
  88. $from_user = $result->from_user;
  89.  
  90. if (!in_array($from_user,$followed)) {
  91.  
  92. $ch = curl_init("http://twitter.com/friendships/create/" . $from_user . ".json");
  93. curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
  94. curl_setopt($ch, CURLOPT_POST, 1);
  95. curl_setopt($ch, CURLOPT_POSTFIELDS,"follow=true");
  96. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  97.  
  98. $apiresponse = curl_exec($ch);
  99.  
  100. if ($apiresponse) {
  101. $response = json_decode($apiresponse);
  102.  
  103. if ($response != null) {
  104. if (property_exists($response,"following")) {
  105. if ($response->following === true) {
  106. echo "Now following " . $response->screen_name . "\n";
  107. } else {
  108. echo "Couldn't follow " . $response->screen_name . "\n";
  109. }
  110. } else {
  111. echo "Follow limit exceeded, skipped " . $from_user . "\n";
  112. }
  113. }
  114.  
  115. }
  116.  
  117. curl_close($ch);
  118.  
  119. } else {
  120. echo "Already following " . $from_user . "\n";
  121. }
  122.  
  123. }
  124.  
  125. }
  126.  
  127. }
  128.  
  129.  
  130. }
  131. }
  132.  
  133. ?>

URL: http://www.davestevens.co.uk

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.