How to get Twitter follower count in PHP

Are you are WordPress developer and want to show twitter follower count on your wordpress blog or you want to show your Twitter follower count on your PHP based site? You might be wondering how to get that number from twitter. So here is the code snippet with details so you can write your own or you can just copy paste this one.

The new Twitter API allows you to read user information in XML and JSON format, so all you have to do is get the information in XML format and read the value between <followers_count> element.

Here is the code snippet for reading twitter followers count in PHP.

<?php
 
$username = "hameedullah";    // Set this to username whose follower count you want to read.
 
$twitter_api_url = "http://api.twitter.com/1/users/show.xml?screen_name=$username";
 
$api = curl_init($twitter_api_url);
curl_setopt($api, CURLOPT_HEADER, 0);
curl_setopt($api, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($api);
curl_close($api);
 
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
    $followers_count = $match[1];
}
 
echo $followers_count;
?>

If you have any issues with the code snippet let me know in comments, or if you are looking for a code to get something else from the Twitter API let me know in comments too.

6 Google Buzz tips to use Buzz as a pro

Google Buzz, a name that has been a buzz word since the launch. It looks like sooner or later people are going to embrace Buzz, those who will embrace it sooner will have an upper edge. Anyway, I am the Buzz admirer and hence I decided to share few cool Buzz tips with everyone, whether you are a Buzz fan or not these tips will be useful for you.

1. Find someone’s comments

Getting to know on what buzz posts your friends have commented allows you to take part in conversations that might interest you, or you might find something useful. You can even find the posts where you have commented for follow up. So lets see how to actually search for the buzz posts commented by someone. You need to use the special operator “commenter:” followed by the username, email or name of the user. Like for example if you know someone’s email address you can use commenter:username@gmail.com or just commenter:username. If you don’t know the uemail address then you can specify name too. Like if you want to search the posts where I have commented you can search for “commenter: Hameedullah Khan”

2. Filter Google Buzz

If you like me don’t want to see Buzz updates in your inbox and keep your inbox and Buzz separated you will definitely love this tip which I first read on LifeHacker. Just create a filter with “label:Buzz” and select “Skip Inbox”. For more detailed step by step tutorial read Hide/Remove Google Buzz Updates from Your Gmail Inbox on lifehacker.

3. Access amazing Buzz for Mobile from your PC

Buzz for mobile not only supports collapsing comments and Buzz but it also allows you to view Buzz updates from the nearby user. By viewing updates from nearby user the opportunities to connect with other people are endless. Try Buzz for mobile here.

4. Search Buzz from specific sources.

While searching Buzz you can specify source of the updates you want to see, for example if you want to see Buzz updates that are posted from Twitter only use “source:twitter” operation in your search query. You can prefix the source operator with hyphen to filter out the Buzz that were posted from Twitter, example: “-source:twitter”

5. Post your Buzz on Twitter

Post your Buzz updates to Twitter in real time, just follow the steps below to setup posting buzz updates to twitter.

  1. Visit http://profiles.google.com/me, which will redirect to your profile
  2. Copy your profile URL (e.g. “http://www.google.com/profiles/dclinton“)
  3. Visit http://feedburner.google.com/ and sign in with your Gmail account
  4. Paste your profile URL under Burn a feed right this instant
  5. Click next and then click Skip directly to feed management
  6. Click the Publicize tab on the top
  7. Click the Socialize tab on the left
  8. Click Add a Twitter Account
  9. Sign in to Twitter and click Allow to allow Feedburner to post
  10. Change Post Content to “Body Only” (important!)
  11. Click Activate

reproduced from work shared by DeWitt Clinton

6. Follow Google Buzz team on Buzz

Follow the Google Buzz team, to stay updated on release of new Buzz features and tips and tricks from the Buzz team.

7. Bonus TIP: Follow me 🙂

You should follow me on Google Buzz, if you want to stay updated on Google Buzz developments and want to learn such new tricks every now and then.

What do you think about these tips? Are they useful? Do you have any tricks to share?

Google just can’t replace twitterfeed for now.

Though I am a fan of Google services but the way it is moving towards establishing its monopoly on the Internet gives me shivers. Many of you might already know about twitterfeed, it is a service that posts your blog updates or feed updates to twitter, not only to Twitter but few more services which includes Facebook too. As of writing this post twitterfeed claims to be feeding 712988 feeds to other services. But that number will decrease sooner or later as Google has released a new feature for their Feedburner service known as Socialize. According to Google,

Connect your feed to the real-time social web! With Socialize, FeedBurner will automatically post updates from your feed to your social media account.

Configuration Limitations

The socialize feature comes with many limitations. It does not allow me to configure the post frequency. It does not allow me use my favorite URL shortner, yes you guessed it, you have to use the Google’s URL shortner goo.gl. It does not allow me add text to the begining and end at the same time.

Have a look at twitterfeed’s configuration options in the screenshot below, you can clearly see the number of URL shortners twitterfeed allows you to use. I can use separate URL shortners for separate feeds, this is awesome:

Twitter Feed Configuration Step 1

Have a look at Feedburner’s configuration options in the screenshot below:

Feedburner Confiuration Options

Posting Limitations

Feedburner can only post to Twitter but twitterfeed can post to other services too which includes Laconica, Hellotxt, Ping.fm and Facebook.

TwitterFeed Configuration Step 2

Users will use whatever they feel comfortable with, there are other services too which post your updates to Twitter which includes FriendFeed too, I myself use FriendFeed. I only wrote this twitterfeed and Feedburner socialize comparison because I read a post from Amit Agarwal who is very senior blogger about switching from twitterfeed to Google, so I decided to write comparing both the services. Now its up to you to decide what service will you use? If you have never used twitterfeed then you may start using Google’s Socialize feature of Feedburner and if you have been using twitterfeed you may want to stay with it.

What service do you use to publish your blog posts to twitter? Do you find it useful to automate the process of publishing blog posts to twitter? Best of luck publishing your blog posts to twitter, no matter what service you use keep posting good stuff to twitter because this is what makes it useful.

P.S: If I am not following you on twitter yet let me know your twitter username in the comments and I will surely follow you.

Here is why the new RT feature of twitter sucks

As we all know that few days ago twitter has introduced new RT feature, and Twitter team specially @ev seems to like the new feature. But do the community like it? Is RT really created by twitter? I as a twitter user do not like the new RT feature. I have my own reasons like other people but I would like to discuss the reason for which any sensible person won’t like twitter.

Like is not ReTweet

RT stands for ReTweet which means tweeting a tweet again because you find it useful and you want to share it with your followers. Now the way new RT feature of twitter works totally negates the definition of RT. Because with new RT feature the tweet is never ReTweeted, it just gets listed in the timeline of a user. The only thing that happens is bunch of meta data gets attached to the tweet. In simple words the new RT feature of twitter works exactly same as “Like” button in Facebook.

Tweet is lost

It looks like Twitter assumes that we watch our twitter timeline whole day even when we are sleeping, but this is not true. When I am sleeping or away from twitter I miss a lot of tweets, though I try to scroll back and read many of them but I don’t always read all of them. This means that I can and will miss some important tweets even if they are RTd by all of the people I follow, because the ReTweeted tweet just do not pop up in the timeline. It stays at its current position and the new meta information is attached. For example if one of your friend Retweeted a tweet while you were sleeping. then after that ReTweet there were like 100 or so tweets in your timeline, you woke up in the morning and started using twitter. You missed that ReTweet because you didn’t scrolled down, now one of your friend gets on twitter and ReTweeted the tweet that was ReTweeted while you were away or sleeping. That ReTweet will not popup in your timeline even your another friend just ReTweeted it, so the ReTweets have lost the value.

Community Response

I have seen many people using the new RT feature and many have stopped using it like me because I think the feature that was introduced by Twitter is not really a ReTweet but Like. I am staying with the old ReTweet and hope that many others will follow as the new ReTweet just don’t work the way it should. If the ReTweeted Tweets start poping to the top then the new ReTweet feature might be somewhat usable but until then the new feature is just not for me. I won’t be ReTweeting anything that will be ReTweeted in my timeline using new ReTweet feature, sorry guys.

I hope Twitter will listen to its users because they are users who have build the twitter and specially the ReTweet was invented by the community not by twitter. I have seen many people switching to alternatives, maybe I will follow the steps too but not in the near future. I hope Twitter team will understand the importance of users feedback and will listen to us and at least I will not have to look for the alternatives.

A mistake that no blogger should ever do

Its been almost a month since I last posted on my blog. First of all I should sorry all of you out there for not being able to updated the blog specially I want to sorry to those who were expecting me to post more posts specially about wordpress. I had been quite busy with some stuff and hence couldn’t update the blog, and I am really sorry for that. I hope I will be able to keep with the pace of changing technology and post useful stuff as soon as I have any.

If you ask any blogger they will say a blog should be updated once a week except if you are posting about something that does not gets updated that frequently. But my blog was about Programming, WordPress, blogging, Twitter and Facebook which is for sure has changed a lot since I last posted. I have missed a lot of things and wasn’t able to keep myself updated with the latest stuff happening special in the social media scene.

Today when I logged on to Facebook I found out that highlights are gone, now they show up in the news feed. Facebook now have a news feed as well as Live feed, I am still not able to figure out difference between the two. But my understanding is the Live Feed thing shows that FriendFeed team is doing their work and Live feed should have real time feed coming. This is surely some great stuff coming out of Facebook and I will write more about new features and updates from Facebook very soon. I am thinking of writing posts on how to use these new features to enhance your Facebooking and use it effectively. Oh by they way, I also like that new ability of Draging and Dropping of news filters.

Twitter seems to have new features too, specially the list feature which is as per my knowledge currently only available to 5% of users. But the list feature will be available to all users from sometime next month. I hope they provide a sensible way of managing and using lists through their web interface. Also I notice Twitter is going pretty hard on spammers because they get them suspended very soon after they register. I got follow notifications from few spammers and as I manually check everyone who follows me and then follow them back if they are human and share useful stuff not just what they had in lunch. Sharing what one had in lunch is also interesting but only if that person shares other useful stuff too.

Stay tuned for more posts coming this week. I will try to do a post daily but only if I will have some useful stuff to write about.

P.S WordPress has been updated too, it is now 2.8.5. I don’t know when the update was released but I just saw the notification at the top, so gotta update too.

5 wordpress plugins that will increase your traffic exponentially

Do you dream like every other blogger out there to get more traffic on your blog? Are you a new blogger that has just setup a blog and now looking to get some traffic? Are you wondering that even you are continuously writing good content but still search engines do not send the traffic like they should, why? Are you sure you are using the right plugins? Here is the list of few wordpress plugins that can get you more traffic.

All In One Seo Pack

This plugin is out of the box SEO tool for your wordpress blog. It allows you to set every aspect of your blog including meta description, meta keywords, title for home page, posts and pages. Not only that but it also allows you to control how the tag and category links are generated. It allows you to have site wide settings and as well as per post settings which makes it even more powerful. This is the must have plugin to help you get your content indexed correctly to rank better in search engines. The better you rank in search engines the more organic traffic you will get.

Google XML Sitemaps

To get traffic from search engines we also need to tell search engines how to find the content on our blog. To tell search engines we need to have an xml sitemap of our blog. All three search engine giants provide a way to manage how they index your site. You can submit your blog sitemap to the search engines so they can discover and index possibly hidden parts of your blog.

Tweetmeme button

As we all know that Twitter is getting more and more popular everyday and everyone is using to find good content, so if you have good content on your site then you should make it easy for your readers to tell their followers about it. Not only will that help your readers have good reputation among their followers for tweeting good stuff but it will get you more traffic. Tweetmeme button very nicely integrates with the blog and tracks how many times your blog post has been re-tweeted. A must have plugin if you are looking to get traffic from Twitter.

Social Bookmarking RELOADED

This plugin add a list of social bookmarking buttons below your posts and/or pages to allow your visitors to easily bookmark your posts and share them with their friends. You can enable/disable bookmarking buttons through the admin interface. The more your readers bookmark your posts the more traffic from those social bookmarking sites will come to your site.

WP-Email

WP-Email allows you to add a link to your posts and pages to allow your readers to recommend your posts to their friends. The more easy you make for your readers to recommend an article to a friend the more your readers will tell their friends and the more traffic will come to your site.

In the next post I will share how can you convert the traffic into loyal readers? What plugins can help you to get the people coming back to your blog? What plugins can help you to get your readers involve in conversation.

Currently I am curious to know that are you already using any of the plugins? How much traffic you get from twitter as compare to other social networking sites? Do not forget to share your experience in the comments.

10 signs you are addicted to twitter

In the last post I talked about signs that shows that you are addicted to Facebook. While I was writing that post I realized it is not only Facebook but one more social network that I am addicted to and that is offcourse twitter. So how is Twitter different from Facebook is another discussion. The signs of addictness are offcourse different then off Facebook. If you have an account on Twitter and have used it you must have been addicted to Twitter. Let me tell you the signs and you will know if you are addicted or not. Below are the 10 signs of Twitter addictness:

  1. You have a twitter client on your cellphone.
  2. You launch your favorite Twitter client as first application after logging into computer.
  3. You compare one Twitter client with the other to find the best one.
  4. You keep hitting Refresh/Update to get new updates in your Timeline.
  5. You check every user’s twitter profile who follow you.
  6. You #hashtag your Facebook updates or text messages.
  7. You always try to tweet good valuable stuff in hope getting RTs.
  8. You check your followers number everyday.
  9. You check your number of updates everyday.
  10. You use third party services to keep track of who is un-following you.

These are the 10 signs I feel are the signs of Twitter addiction, if you feel that there are other signs that shows Twitter addiction or I have added something which is normal and not sign of addiction let me know in the comments.

P.S Did I mention that my username on twitter is @hameedullah and you can follow me on twitter.

How to use oauth-python-twitter

Using OAuth for authentication is quite different then using Basic Auth in many ways, first major difference is that one don’t know the username until it is requested from twitter after completing the authentication process.

Details

You will need following information to start.

  • Consumer Key
  • Consumer Secret

If you do not have above, you can request them from here: http://twitter.com/oauth_clients

The following are the steps that should be performed to authenticate user and get user information from twitter, the rest is same as using python-twitter.

  • Get the Request Token from twitter
  • Get Authorization URL
  • Get the Access Token from twitter
  • Get user information

Get the Request Token from twitter

twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET)
 
request_token = twitter.getRequestToken()

Get Authorization URL

using same request_token from previous step

authorization_url = twitter.getAuthorizationURL(request_token)

Now send the user to authorization URL, for allowing access to the application.

Get the Access Token from twitter

Once the user return from twitter, we need to request the access_token from twitter for futher aunthenticated api calls on behalf of user.

NOTE: Need to create the new instance of OAuthApi using request_token from first step.

twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token)
 
access_token = twitter.getAccessToken()

Get user information

This api call was not present in python-twitter and the user info call expected that there we know the username before making call, but this is not the case with OAuth, so we have to request User Information so we can use it in our application.

NOTE: Need to create the new instance of OAuthApi using access_token from last step.

twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
 
user = twitter.GetUserInfo()

Now use the rest of python-twitter api calls as you used to use them with basic authentication, for more information see the wiki at:http://code.google.com/p/python-twitter

OAuthApi, an OAuth Extension to python-twitter

If you are a python developer and you tried to develop some application for twitter, you must have came acrossed python-twitter. Which provides you a pythonic interface to twitter, by allowing you to access almost all twitter objects as python objects. python-twitter is still in devleopment, and hence still does not have the OAuth compatibility. I am being a oauth pro, deicided to write a derived class from python-twitter, to allow OAuth to be used as the authentication mechnism for python-twitter.

python-twitter is being developed by our beloved google’s employee: DeWitt Clinton

You can get the python-twitter at: python-twitter

You can get the oauth extension to python-twitter at: oauth-python-twitter

In the next following posts I will posting about how I am using it with Django specifically and how I have writter my TwitterAuthBackend for Django. The whole purpose of publishing the code is to get improvements and reviews on the code, so I have allowed non-members to review the above project on code.google.com, you are more then welcome to post your coments here or review the code on the project. Let me know if you don’t understand anything by asking questions in comments.

P.S I have used the same license as was used for python-twitter.

Happy twittering and developing 🙂