/ Published in: PHP
Simple PHP script which allows you to specify your twitter log in details and a search term, then automatically follow users who have tweeted that term. Code is released as Open Source, use it as you wish - please leave my URL in the commented section though.
Expand |
Embed | Plain Text
<?php // Twitter Auto-follow Script by Dave Stevens - http://davestevens.co.uk // Set the twitter user $user = ""; $pass = ""; // Set the term you want to follow (e.g. "soccer") $term = ""; // Get already followed $userApiUrl = "http://twitter.com/statuses/friends.json"; $ch = curl_init($userApiUrl); curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $apiresponse = curl_exec($ch); curl_close($ch); if ($apiresponse) { $json = json_decode($apiresponse); if ($json != null) { foreach ($json as $u) { $followed[] = $u->name; } } } $userApiUrl = "http://search.twitter.com/search.json?q=" . $term . "&rpp=100"; $ch = curl_init($userApiUrl); curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $apiresponse = curl_exec($ch); curl_close($ch); if ($apiresponse) { $results = json_decode($apiresponse); $count = 20; if ($results != null) { $resultsArr = $results->results; foreach ($resultsArr as $result) { $from_user = $result->from_user; $ch = curl_init("http://twitter.com/friendships/create/" . $from_user . ".json"); curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,"follow=true"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $apiresponse = curl_exec($ch); if ($apiresponse) { $response = json_decode($apiresponse); if ($response != null) { if (property_exists($response,"following")) { if ($response->following === true) { } else { } } else { } } } curl_close($ch); } else { } } } } } ?>
Comments
Subscribe to comments
You need to login to post a comment.

Hey I have modified the php code just a bit to enable a person to add their own details on a webpage and it will process it on the same webpage.
Here is my code:
Twitter Follow Script - Jonathon Maguire
Twitter Follow Script
div { border: .2em dotted #900; }
border {
border-width: .2em; border-style: solid; border-color: red; }
Username:
Password:
Search Term