twitter auto follow


SUBMITTED BY: Guest

DATE: March 14, 2014, 8:55 a.m.

FORMAT: PHP

SIZE: 2.2 kB

HITS: 1726

  1. <?php
  2. // Twitter Auto-follow Script by Dave Stevens - http://davestevens.co.uk
  3. $user = "";
  4. $pass = "";
  5. $term = "";
  6. $userApiUrl = "http://twitter.com/statuses/friends.json";
  7. $ch = curl_init($userApiUrl);
  8. curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
  9. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  10. $apiresponse = curl_exec($ch);
  11. curl_close($ch);
  12. $followed = array();
  13. if ($apiresponse) {
  14. $json = json_decode($apiresponse);
  15. if ($json != null) {
  16. foreach ($json as $u) {
  17. $followed[] = $u->name;
  18. }
  19. }
  20. }
  21. $userApiUrl = "http://search.twitter.com/search.json?q=" . $term . "&rpp=100";
  22. $ch = curl_init($userApiUrl);
  23. curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  25. $apiresponse = curl_exec($ch);
  26. curl_close($ch);
  27. if ($apiresponse) {
  28. $results = json_decode($apiresponse);
  29. $count = 20;
  30. if ($results != null) {
  31. $resultsArr = $results->results;
  32. if (is_array($resultsArr)) {
  33. foreach ($resultsArr as $result) {
  34. $from_user = $result->from_user;
  35. if (!in_array($from_user,$followed)) {
  36. $ch = curl_init("http://twitter.com/friendships/create/" . $from_user . ".json");
  37. curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
  38. curl_setopt($ch, CURLOPT_POST, 1);
  39. curl_setopt($ch, CURLOPT_POSTFIELDS,"follow=true");
  40. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  41. $apiresponse = curl_exec($ch);
  42. if ($apiresponse) {
  43. $response = json_decode($apiresponse);
  44. if ($response != null) {
  45. if (property_exists($response,"following")) {
  46. if ($response->following === true) {
  47. echo "Now following " . $response->screen_name . "\n";
  48. } else {
  49. echo "Couldn't follow " . $response->screen_name . "\n";
  50. }
  51. } else {
  52. echo "Follow limit exceeded, skipped " . $from_user . "\n";
  53. }
  54. }
  55. }
  56. curl_close($ch);
  57. } else {
  58. echo "Already following " . $from_user . "\n";
  59. }
  60. }
  61. }
  62. }
  63. }
  64. ?>

comments powered by Disqus