Tweet Something from Your Website Using bitly REST Api

Oho, did I actually write the right title of this post? Bit.ly is not for tweeting, it’s for shortening the long URLs right, but hey, why bit.ly is so popular now? Most common answer could be twitter. I don’t know if people would used this service that much if there wasn’t twitter. Anyways, this is very important to shortening something in your tweet as twitter has character limits. So let’s see how we can actually tweet something from a website using this REST based Api method calls.

Note one thing that if your site is using wordpress or any kind of CMS that allows to use plug-ins then you don’t have to worry about it. This is something you can use only for updating some content to twitter from your site. Hope I made it clear at first….

After digging bitly apis, I think its pretty easy to do it as bitly provides Javascript client library so there shouldn’t be any varier about back-end language. So let’s see how easily we can tweet some content from our site.

First of all, if you redirect anything with the following URL, twitter will get your message in the text box and all you have to do is, just press the update button.

http://twitter.com/home?status=your_message_comes_here

So our message has to be customized and you cannot allow anybody to send message more than 140 chars right. This is why we will use bitly api to customized it.

First of all, we have to add the API library with the following format.

<script type="text/javascript" charset="utf-8" src="http://bit.ly/javascript-api.js?version=latest&login=junal&apiKey=R_888fefa724b856672a3276a3905d8e30"></script>

you need to login to get user name and password from bitly, though you can use demo user name and apikey from here but later you have to use your own authentication information.

Anyways, we are done connecting with bitly by including their JS client library. Now let’s create some functions of our own to call them. Open a JS file and paste the following there, you can find this example codes in the bitly documentation.

var TweetAndTrack = {};
TweetAndTrack.open = function(targ, url) {
var callback_name = url.replace(/\W/g, '');
BitlyClient.call('shorten', {
'longUrl': url,
'history': '1'
}, 'BitlyCB.' + callback_name);
return false;
};
 
TweetAndTrack.popResult = function(data) {
// Results are keyed by longUrl, so we need to grab the first one.
for (var r in data.results) {
return data.results[r];
 }
};

now it’s time to create our own function to call. Here is the example one…

function tweetMe(msg, url) {
var textMessage = msg.replace(new RegExp("^(.{0," + 80 + "}\\b).*"), "$1");
var callback_name = url.replace(/\W/g, '');
BitlyCB[callback_name] = function(data) {
var result = TweetAndTrack.popResult(data);
var tweet_url = "http://twitter.com/home?status=" + encodeURIComponent(textMessage+ "... " + result.shortUrl );
window.open(tweet_url);
};
 
BitlyClient.call('shorten', {
'longUrl': url,
'history': '1'
}, 'BitlyCB.' + callback_name);
 
return false;
}

I have used regular expression here to truncate the message. I kept the length of the message 80! why? Because, your URL will take some chars as well and you should also keep some space for people who will retweet your tweet :)

Now, we have to call this javascript function called “tweetMe()” and it has 2 params right. We have to pass the message and the url along with the message and bit.ly api will make sure that whatever we are sending, it will be customized before sending. So how can we call this function?

<a href=”#” onclick=”return tweetMe(’Content or message of your tweet‘, ‘URL of your along with your message‘);”>tweet this </a>

Ok, now just click on “tweet this” and then you it will take you to the twitter heaven. Be happy there, and ask me any questions if you can’t reach there ;)

[Post to Twitter] 

আর মাত্র কয়েক ঘন্টা, তারপর একজনের সাথে দেখা হবে…

এই সেই একজন যার কথা আগে কোথাও বলিনি, কেন বলিনি ঠিক জানিনা, বলার মত কিছু ছিল বলেও মনে হয়না। যদিও ওর কাজ নিয়ে  ব্লগ লিখছি কিন্তু মুখ ফুটে কখন বলিনি এই মেয়েটিকে কত ভালোবাসি। ৫ বছর আগের কথা, দেশে এসেছিলো কানাডা থেকে। কি এক ওজানা কারনে ভাল লেগে গেল।বলে ফেললাম [কি বলেছিলাম না হয় নাই বললাম..হে হে] ….এইতো হয়ে গেল। তারপর ও চলে গেল কানাডায় আর আমি পড়াশুনা আর কাজ চালিয়ে যেতে লাগলাম…

সেইথেকে, সবসময় যোগাযোগ ছিল….আর যোগাযোগের মাধ্যম ছিল স্কাইপ, এমএসএন…এইভাবে ৫ টি বছর কেটে গেল! তাই আমার মনে হয় প্রিয়জন কাছে না থাকার যন্ত্রনা আমার চেয়ে কেউ ভাল বলতে পারবেনা। যাইহোক, সেই কষ্টের কথা বলার জন্য আজ লিখছিনা…

কাল ভোর ৬ টায় ও ঢাকায় পৌছবে! এ এমন একটা মুহুর্ত যেটা ঠিক বুজাতে পারবোনা। ওকে রিসিভ করার জন্য আমি ভোর ৫ টায় জিয়া ইন্টঃ এয়ারপোর্ট চলে যাব…একটা নিস্তবদতা পেয়ে বসছে নিজের ওজান্তেই

আর মাত্র কয়েক ঘন্টা, তারপর ওর সাথে আমার দেখা হবে…

[Post to Twitter] 

Quiz Monster is Really a Monster for Your Facebook Homepage!

We don’t believe in what our horoscope says, but still want to have a look at our daily horoscope. We don’t believe in astrologist, but still when someone wants to see our palm and tell us the future, we don’t mind eh?

We always have this curiosity to know about ourselves, things that yet to come are mostly make us curious. Some examples are…

Ah, ok i’m stopping….. but, do all these make you annoyed? Aren’t these questions  like your horoscope that you don’t believe but you don’t mind to check it out?

Well, these are the facts why “Quiz Monster” is so popular now. I was hiding all these applications since redesigned facebook launched and lately, I have realized that I can’t actually stop these news feed by hiding one or few applications. Why ? Because this application allows you to create another quiz application! with another freaking question! So, that means I have to wait until my friends decide “ok we have had enough“. And till then I have to face this monster on my home stream.

But hey, Quiz Monster played really well with us. We cant blame it directly right. It’s our friends who are creating another quiz application to check out his/her next curiosity. Got to say well done Quiz Monster!

[Post to Twitter] 

Presenting “Developing Facebook Application” at PHPExperts Semianr 2009

Today, I was really honored to present “how to develop facebook application” at PHPExperts Semianr 2009. Indeed, that was a great experience for me to be in front of bunch of talent guys from whole Bangladesh. Though, it was not possible to show all important points/notes/stories by one presentation at a time, so my target audience were those who were willing to start developing facebook application and my aim was to make it as simple as possible, so that they can start…..

I dont know how successful I was for this…but I will be really happy if I see people are getting interest about developing facebook application.

Personally, I’m very much thrilled after this seminar, because I met lots of people I know from twitter, friendfeed or facebook. Now, i’m pretty sure we have this natural bonding between us. I would like to thank everybody whom I met or who enjoyed my presentation. Your suggestions are always welcome to me. If I ever get any chance again in any other seminar, I will try to talk about advance facebook application developing.

Thanks to all PHPExperts!

DOWNLOAD the source codes of the example i showed in the presentation

Check out the reference from here

[Post to Twitter] 

Twitter Desktop Client War Between TweetDeck and Seesmic!

I have just played with Seesmic new twitter desktop client. Though i have been using TweetDeck for last couple of months. Just wanted to try out the new twitter desktop client as there is a huge buzz about it on twitter and friendfeed. So, what’s so difference between TweetDeck and Seesmic? Well, everything is almost same just facebook integration on new Seesmic desktop client simply rocks. But wait, you gotta call Seesmic a clever jack! Why? Because they just used the new “Open Stream API” and “Facebook for Adobe AIR” very smartly. Facebook Open Stream API was just released a few days ago.I just think if TweetDeck’s last release was little bit delayed it would be great for them. Because then, they would include all these stuffs that Seesmic added. I’m pretty sure now TweetDeck will move it’s ass really fast to get all these new facebook api features enabled in their stomach. And well, facebook made a great move allowing developers to access users’ home stream. Seesmic is the latest result of that move and we gotta wait to see more applications based on this new API. By the way, I’m enjoying Seesmic client for now, let’s have a look at some screenshots.


and well, I guess war is just begun. I asked TweetDeck on twitter to know if they are gonna add new Seesmic’s features in their next version. and they said there will be “big differences in the next version, we have different path“. Smart answer Tweetdeck!

I’m sure next version of TweetDeck is gonna be exciting. What do you think?

[Post to Twitter] 

There is Something Wrong, But…

Google Reader Unread...

Google Reader Unread...

…good thing is, I know what it is.

My Google reader usually don’t miss me that much. At most 3/4 days? And then I read my all favorite bloggers posts on my Google reader. And my blog? I guess, on an average I post one blog per week.

BUT, it’s been more than a month I haven’t even opened my Google reader, blogging really less and it remind me when people ask me why I have no new post. And then I make plan to write something on new Facebook API, maybe more something about Friendfeed and twitter, or how facebook is making mistake fighting with twitter? Or maybe what i’m enjoying from learning python? Well, I know there are lots of things I can write about. There are lots of arguments I can make. Lots of things to talk about….

at the same time, I have learned from my little experience that “don’t write, when your life in pain“. I don’t know if I used the right word, this is something personal. Yes, I have been in a personal issue (i’m not calling it a problem). I know, I never been opened with my personal stuff on any where on the web but like, this is something that keeping me away from all “daily extra activities” . Though im still active on twitter and friendfeed!

And, I’m promising to everybody that soon, I will be open with the issue….i hope this will make me more open and fair to everybody.

p.s: this is nothing related to my work, i’m happily working with my friends :)

[Post to Twitter] 

An Excellent Day and A Guilty…

Today was bangla new year (1416), and at least for this day I don’t stay at home. Last year I was in my hometown sylhet. I wrote a blog on last year’s experience though it was mostly about my bald head fun :) This year I stayed here in dhaka and went out with friends. Place was banani, where a new year fair was organized by AIUB. My friend had  “Rgb Unmad” stall so we all were chilling there. Intension? Well, of course all beautiful girls with sharees ;)

Anyways, this is one of our best cultures that brings all Bangladeshis together. Probably, this is why I like “pohela boishakh” or Bangla new year so much. I was glad to see a successful event organized by AIUB. Whole day was fun…..let’s look at some pictures. Though these pictures don’t show the actual joys but still….

Biscope, still here!

Biscope, still here!

Bauls on the stage

Bauls on the stage

Habib on stage

Habib on the stage

Concert was great!

Concert was great!

but guilty? Well, look at the pictures bellow, I took the left one in the morning. A live flower right?

A flower

A flower

Chondona

Chondona

And right picture was taken when event was over and we were gossiping. Difference between them? Right one you see, her name is “chondona” , she collects empty bottles and sale them for food. I asked how much she actually earn from these empty bottles. 6-7 tk, she said. Only 6/7 tk? Didn’t say anything to her, I looked at my cigarette that was in my hand. That was cost 5 taka. I was leaving them in the air with lots of peace in my mind eh? On the other hand chondona, collects these bottles and then she walks a mile to sale them…and then she gets 6-7 taka – sigh!

[Post to Twitter]