Tweet button with a callback – How to?

Hi Guys,

While I was working on a plugin for WordPress I have to write fair bit of code to get the social stuff happening. Callbacks are necessary from all the major Social buttons that users interact with. Be it Facebook, Google Plus, Twitter or LinkedIn.

In this post I will show you exactly how to add a Twitter’s Tweet button with a callback  in your page that will print “Tweet successful” on Javascript Console once user tweets.

1. The Markup

Everything that I will show here is from Twitter

You should change all the data values in the code as per your requirements

Next steps is to include twitter Javascript API

 

 

2. Twitter API

Put this code somewhere in your body tag

Now that we have window.twttr object available its time to bind some events supported by twitter

3. Event Handler

Place this code before the body end tag and after the above code, but that’s just me saying that

As you can see that its that simple. I can go on and explain other events stuff here too but its just me re-writting what Twitter documentation already have for you. So just go and check it out here

https://dev.twitter.com/docs/intents/events

I hope that this helps

 

 

Comments

  1. Thanks its working. But Sir i need to show alert box on my website after successful tweet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.