My tweet button submits are not shortening the submitting page's url


#1

My tweet buttons have problems with the shortening urls. The code is shown below

On standard status update links, the link is not being shortened and is therefore exceeding the 140 characters. On submission, I am getting the “ops! Your tweet was over 140 characters.” message. Why is the t.co shortener not working.

On type=“IN/Share” script for the button, the data-url is being ignored altogether. N link shortened or otherwise is displayed on the message UI.

The code used can be found here dev1.mycountdown dot org/test.html

My status update button

 <a style="text-decoration:none;margin:0px 0px;padding:0px 0px;text-decoration:none;" href="http://twitter.com/home?status=118 days, 6 hours, 0 minutes until I am eighteen+%28http%3A%2F%2Fmycountdown.org%2Ffullpage.php%3Fcp3_Hex%3DFFB200%26cp2_Hex%3D818181%26cp1_Hex%3D000000%26ham%3D0%26img%3D%26hbg%3D1%26hfg%3D0%26sid%3D0%26fwdt%3D150%26text1%3DI+am+eighteen%26text2%3DHappy+Birthday%26group%3DSpecial+Day%26countdown%3DBirthday%26widget_number%3D3010%26event_time%3D1327536000%29" alt="Share on Twitter" title="Share 118 days, 6 hours, 0 minutes until I am eighteen on twitter" rel="nofollow" target="_blank" class="twitter"><img border="none" src="/images/twitter-icon_small.png"></a>

My tweet count button

script type="IN/Share" data-url="http%3A%2F%2Fmycountdown.org%2Ffullpage.php%3Fcp3_Hex%3DFFB200%26cp2_Hex%3D818181%26cp1_Hex%3D000000%26ham%3D0%26img%3D%26hbg%3D1%26hfg%3D0%26sid%3D0%26fwdt%3D150%26text1%3DI+am+eighteen%26text2%3DHappy+Birthday%26group%3DSpecial+Day%26countdown%3DBirthday%26widget_number%3D3010%26event_time%3D1327536000" data-counter="top"></script></td><td><script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><span style="padding-left:0px;width:30px;padding-right:10px;vertical-align:bottom"><a href="http://twitter.com/share" class="twitter-share-button" 
      data-counturl="http://mycountdown.org/fullpage.php?cp3_Hex=FFB200&cp2_Hex=818181&cp1_Hex=000000&ham=0&img=&hbg=1&hfg=0&sid=0&fwdt=150&text1=I am eighteen&text2=Happy Birthday&group=Special Day&countdown=Birthday&widget_number=3010&event_time=1327536000" 
      data-text="118 days, 6 hours, 0 minutes until I am eighteen"
      data-via="mycountdown"
      data-count="vertical">Tweet</a>

#2

Few things here:

You’re mixing two APIs together with an additional antiquated mode of tweeting. The Tweet Button doesn’t use “IN/Share” script types, the LinkedIn API does though.

Your href for Tweeting isn’t well formed:
http://twitter.com/home?status=118 days, 6 hours, 0 minutes until I am eighteen+%28http%3A%2F%2Fmycountdown.org%2Ffullpage.php%3Fcp3_Hex%3DFFB200%26cp2_Hex%3D818181%26cp1_Hex%3D000000%26ham%3D0%26img%3D%26hbg%3D1%26hfg%3D0%26sid%3D0%26fwdt%3D150%26text1%3DI+am+eighteen%26text2%3DHappy+Birthday%26group%3DSpecial+Day%26countdown%3DBirthday%26widget_number%3D3010%26event_time%3D1327536000%29"

That’s an antiquated way to create a Tweet for a user, besides having some errors in encoding of the status and better ways to accomplish your goals.

Try using the Tweet Button/Tweet Intent’s distinct parameter for the URL and ensure you’re encoding characters like " " as “%20”.

As best as I can guess, you want something more like this for sharing on Twitter.


#3

I am urlencode the message string and the url is now url=

Following your syntax I get no url at all.

check the right most twitter button

http://dev1.mycountdown.org/tag.php?tag=harry+potter+two

#4

The URL you’re generating and passing to the Tweet Intent is still not encoded quite right – since the original URL has “+” characters in it, they need to be re-encoded when passing it as a URL parameter:

https://twitter.com/intent/tweet?text=Harry+Potter+Two+Film+release+countdowns&url=http%3A%2F%2Fdev1.mycountdown.org%2Ftag.php%3Ftag%3Dharry+potter+two

Should be:

https://twitter.com/intent/tweet?text=Harry+Potter+Two+Film+release+countdowns&url=http%3A%2F%2Fdev1.mycountdown.org%2Ftag.php%3Ftag%3Dharry%2Bpotter%2Btwo


#5

Thanks for the comment.

I am puzzled, the url is straight output of the php urlencode() function…What do you use to encode urls?


#6

Ah, just tested the html link button encoding spaces separately to urlencode, and the links are now being published. Curiously I am not getting a t.co redirect, but the link is handled as a unit a single character long.

Even with the newly encoded url, the javascript twitter button in the middle of the page is still ignoring data-url links. The countup is working but not the link shortener. Cannot see what I am doing wrong there either…?

Thanks again for your help

Paul


#7

Solved the problem

Basically twitter javascript requires custom url encoding, as follows

$countdown_url_encode = urlencode($countdown_url); $countdown_url_encode = str_replace("+","%2B", $countdown_url_encode); Works on the html twitter button

For the javascript button, the url must be further encoded as follows:

$countdown_url_encode = str_replace("%3F","?",$countdown_url_encode); $countdown_url_encode = str_replace("%2B","+",$countdown_url_encode); $countdown_url_encode = str_replace("%3A",":",$countdown_url_encode); $countdown_url_encode = str_replace("%2F","/",$countdown_url_encode); $countdown_url_encode = str_replace("%23","#",$countdown_url_encode);

best discussion thread is


#8