Twitter Button count keeps resetting to 0
I wrote a script in javascript that injects the twitter button url into the DOM because the URL I share includes a dynamic parameter. That part works.
What doesn't work is the twitter count. It keeps resetting to 0.
Here is how I build the twitter button URL.
var appendEl = document.getElementById(el),
twitterScript = document.createElement('a'),
share_url,
defaults,
text_length_allowed = 110,
text_length;
opts = opts || {};
defaults = {
text: ''
};
for (var key in defaults) {
if (defaults.hasOwnProperty(key) && opts[key] === undefined) {
opts[key] = defaults[key];
}
}
text_length = opts['text'].length;
if(text_length > text_length_allowed) {
custom_text = opts['text'].substring(0, text_length_allowed) + '...'开发者_如何学C;
} else {
custom_text = opts['text'];
}
share_url = this.shareUrlHelper(shareUrl);
share_url = share_url + 'random_tag=' + this.randomTag;
twitterScript.setAttribute('href', 'http://twitter.com/share?text=' + escape(custom_text) +
'&url=' + encodeURIComponent(share_url) + '&counturl=' + encodeURIComponent(shareUrl)) +
'&count=horizontal';
twitterScript.setAttribute('class', 'twitter-share-button');
twitterScript.innerHTML = 'tweet';
appendEl.appendChild(twitterScript);
var tweetButton = new twttr.TweetButton(twitterScript);
tweetButton.render();
I passed in these parameters: text, url, counturl, count.
url is the URL with my dynamic parameter appended to it, and counturl is the URL with no parameters.
What am i doing wrong?
since it's a dynamic URL, it will keep resetting to 0 because twitter does the count based on the URL
精彩评论