开发者

jquery plugin or routine to find tweet count

开发者 https://www.devze.com 2023-02-11 14:11 出处:网络
I am looking for a headstart to implement a custom tweet-counter for my Rails app. Using tweet button gives me the option to either use the twitter-syled button+counter, or use a custom link, withou

I am looking for a headstart to implement a custom tweet-counter for my Rails app.

Using tweet button gives me the option to either use the twitter-syled button+counter, or use a custom link, without counter.

What I'd like to achievem is to add a counter to a simple <a href="http://convoluted?tweet=url">tweet this</a> url.

e.g. tweet this → jQuery → tweeted 123 times, tweet this

For that, I need to simply parse the Json from http://urls.ap开发者_开发知识库i.twitter.com/1/urls/count.json?url=http://example.com&callback=twttr.receiveCount and update the DOM with that counter.

My jQuery is poor and rusty, so I'd love to find a headstart with some example code to go by. Any hints? Or existing libraries? Or projects where I can look into the code that have this covered?


Sorry misread you need to make a jsonp request as mkoryak already described. Only showed the integration for the counter but that shouldn't be a problem either.

-

easy as this:

function twttr.receiveCount(input) {
   var data = $.parseJSON(input);
   // Find the appropriate Element and insert the Counter before
   $('#counter').insertBefore('tweeted '+data.count+' times');
}

Only thing to change - you need to add a id to your link or create a placeholder-div for the counter.

Example for the placeholder-div:

<div id="counter"></div><a href="http://convoluted?tweet=url">tweet this</a>


you need to make a jsonp request.

There is a blog post that talks about it here:

http://jquery-howto.blogspot.com/2009/04/twitter-jsonjsonp-api-url.html

also, this probably does exactly what you need:

http://www.w3avenue.com/2010/02/24/how-to-get-digg-delicious-and-tweet-counts-using-jquery/

0

精彩评论

暂无评论...
验证码 换一张
取 消