Twitter Tweet Button does not count
I am using the official Tweet Button from Twitter to allow users to share my site.
The button itself is working just fine, however the counter doesn't work and stays at zero all the time. (after you tweet, it is incremented client-side, but if you press F5, it will be zero again)
This is my really simple code to include the button:
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.whattheplace.com/Show/1/" data-count="vertical">Tweet</a>
<script type="text/javascript" src="http://p开发者_Go百科latform.twitter.com/widgets.js"></script>
The specified URL (http://www.whattheplace.com/Show/1/) is a regular URL returning a web page with HTTP code 200, i.e. no redirection or the like that could maybe confuse Twitter.
I've prepared a small example on http://www.whattheplace.com/static/tweetbutton.html where you can see the problem. On the "real" page at http://www.whattheplace.com, the Tweet Button is wrapped by AddThis, but the problem is exactly the same.
I'm thinking that it might have something to do with the new Twitter URL shortener (t.co), however I can't prove it and it seems to work on other people's pages just fine.
There are a few possible problems related to this. One of them is that if the link is shortened, Twitter won't add it up unless you add the "counturl" url property.
Also, Twitter doesn't count the tweets coming from protected accounts (accounts that don't share their tweets).
Please let me know if none of this offers the solution.
Cheers!
Something else to bear in mind is that the tweet counts are not accurate in real time. They are cached and updated asynchronously. See http://dev.twitter.com/pages/tweet_button_faq#count-api-increment
I had luck switching from the URL parameter method to the data- attributes method.
function twtrButton(url, text, configs){
// Create a link
var params = {
rel: 'canonical',
'data-count': 'horizontal',
href: 'http://twitter.com/share/'
};
if (url) {
params['data-url'] = url;
params['data-counturl'] = url;
}
if (text) {
if(text.length > 90){
text = text.substring(0, 90);
text += '...';
}
params['data-text'] = text;
}
if (configs) {
if (configs.via) {
params['data-via'] = configs.via;
}
if (configs.related) {
params['data-related'] = configs.related;
}
}
var link = $('<a>', params).addClass('twitter-share-button');
return link;
}
This snippet assumes jQuery 1.5 or greater.
I had this problem too and found out that it was related to the value of the "canonical" link tag I had set. It was set to http:// www.iphone4simulator.com but tweet button was sharing http://iphone4simulator.com because I had set my DNS servers to remove www string from the address. As soon as I changed the canonical URL value in the markup to the latter, the button worked like a charm!
I think you are missing data-via="#"
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.whattheplace.com/Show/1/" data-count="vertical" data-via="#">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
If its rapped around the add this im quite sure you should "mix" it with the twitter button itself, shouldn´t you be using something like:
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
<a class="addthis_button_tweet"></a>
<a class="addthis_counter addthis_pill_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=viralizate"></script>
<!-- AddThis Button END -->
I´m not finding the question clear enough, hope it helps anyway! if you explain further i will gladly edit it! - if i know the answer ;)
Good luck!
Trufa
you must use both "data-count" AND "data-url" if you want to show a count and there is a url shortener involved (and there always is):
data-url="http://dev.twitter.com/pages/tweet_button"
data-count="vertical"
it's not data-url, since that's the shortened url... you don't have to bother including that i don't think. set data-counturl=THE_PAGES_ACTUAL_URL so irregardless of what shortener someone uses, the count for your actual url gets incremented and displayed. so something like this... data-counturl="<?php echo $_SERVER['PHP_SELF']; ?>"
--- ummm... nevermind, i spoke too soon...
精彩评论