1 – Autofollow script (PHP)
This code allow you to automatically follow user who have tweeted about a specific term. For example, if you want to follow all users who tweeted about php, simply give it as a value to the $term variable on line 7.
<?php
// Twitter Auto-follow Script by Dave Stevens - http://davestevens.co.uk
$user = "";
$pass = "";
$term = "";
$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);
$followed = array();
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;
if (is_array($resultsArr)) {
foreach ($resultsArr as $result) {
$from_user = $result->from_user;
if (!in_array($from_user,$followed)) {
$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) {
echo "Now following " . $response->screen_name . "n";
} else {
echo "Couldn't follow " . $response->screen_name . "n";
}
} else {
echo "Follow limit exceeded, skipped " . $from_user . "n";
}
}
}
curl_close($ch);
} else {
echo "Already following " . $from_user . "n";
}
}
}
}
}
?>
Source : http://snipplr.com/view/17595/twitter-autofollow-php-script/
2 – Get the number of follower in full text (PHP)
When you have a website or blog and use Twitter, it can be cool to display how many followers you have. To do so, simply use the short code snippet above.
Note that if you want to integrate the same code into WordPress, using caching, Rarst have written a nice code that you can get using the link after the snippets (Rarst code is in the comments, so scroll down a bit)
<?php
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=catswhocode');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
echo $tw['count'];
?>
Source : Rarst on http://www.wprecipes.com/display-the-total-number-of-your-twitter-followers-on-your-wordpress-blog
3 – View who doesn’t follow you (Python)
Some people don’t like the idea of following people who don’t follow you back. If you recognized yourself in this statement, there’s a huge amount of chances that you’ll enjoy the following Python code snippet.
Simply type your Twitter username and password on line 4 and call the file using the Python interpreter.
import twitter, sys, getpass, os
def call_api(username,password):
api = twitter.Api(username,password)
friends = api.GetFriends()
followers = api.GetFollowers()
heathens = filter(lambda x: x not in followers,friends)
print "There are %i people you follow who do not follow you:" % len(heathens)
for heathen in heathens:
print heathen.screen_name
if __name__ == "__main__":
password = getpass.getpass()
call_api(sys.argv[1], password)
Source : http://blog.davidziegler.net/post/107429458/see-which-twitterers-don-t-follow-you-back-in-less-than
4 – Update your Twitter status…using Vim
The Vim editor is one of the most powerful and complete text editor available. This command, allowing you to update your Twitter status, is just one more proof.
command -range Twitter, write ++enc=UTF-8 !curl --data-urlencode status@- --netrc --no-remote-name http://twitter.com/statuses/update.xml
Source : http://snipplr.com/view/16550/vim-command-to-post-to-twitter/
5 – Get Your Most Recent Twitter Status (PHP)
A simple PHP function that get your latest Twitter status so you can display it on your blog or website.
<?php
function get_status($twitter_id, $hyperlinks = true) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$src = curl_exec($c);
curl_close($c);
preg_match('/<text>(.*)</text>/', $src, $m);
$status = htmlentities($m[1]);
if( $hyperlinks ) $status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href="
Oct 6, 2009
cosmos
category :
Visited 1283 , 4 Today