Twitter callback for multiple follow buttons: bind unique function on follow event for each individual Follow button?


#1

I want to use Twitter’s web intents to create multiple follow buttons on the same page and create a unique cookie (let’s say cookie1 for button 1, and cookie2 for button 2) every time the visitor clicks one of the Follow buttons.

What happens with the current code is that all the cookies get created instantly after clicking one of the Follow buttons, rather than a single cookie for the user that gets followed (ie ‘cookie1’ when user1 gets followed, ´cookie2’ when user2 gets followed etc.)

This is my current code. Imagine it 3 times for user1, user2, and user3. I’m including Twitter widget-js for web-intents in the header.

    <a href=http://twitter.com/user1 class='twitter-follow-button'   data-show-count='false' data-size='large'>Follow @user1</a>
	    
	    <script>
	    twttr.ready(function (twttr) {
	      twttr.events.bind('follow',   function(e) {
				document.cookie =  'cookie1=1; expires=Fri, 3 Aug 2999 13:33:37 UTC; path=/';
				setTimeout('location.reload();',1000);
	      });
	    });
</script>
	    </code>

#2

You should not have 3 event handlers, but one. The event handler can know what button was pressed with for example e.data.user_id and e.data.screen_name (e being the first parameter to the event handler).
More details there: https://dev.twitter.com/docs/intents/events#events


#3