How do you include hashtags within Twitter share link text?

≡放荡痞女 提交于 2019-12-02 17:29:35
adamb0mb

It looks like this is the basic setup:

https://twitter.com/intent/tweet?
url=<url to tweet>
text=<text to tweet>
hashtags=<comma separated list of hashtags, with no # on them>

This would pre-built a tweet of: <text> <url> <hashtags>

The above example would be: https://twitter.com/intent/tweet?url=http://www.example.com&text=I+am+eating+branston+pickel+right+now&hashtags=bransonpickel,pickles

There used to be a bug with the hashtags parameter... it only showed the first n-1 hashtags. Currently this is fixed.

I may be wrong but i think the hashtag has to be passed as a separate variable that will appear at the end of your tweet ie:

http://www.twitter.com/share?url=www.example.com&text=I+am+eating+branston+pickel+right+now&hashtag=bransonpickel

will result in "I am eating branston pickel right now #branstonpickle"

On a separate note, I think pickel should be pickle!

Cheers

Toby

If you're using PHP, you can use the following:

<?php echo 'http://www.twitter.com/share?' . http_build_query(array(
    'url' => 'http://www.example.com',
    'text' => 'I am eating #branstonpickel right now'
)); ?>

This will do all the URL encoding for you, and it's easy to read.

For more information on the http_build_query, see the PHP manual: http://us2.php.net/http_build_query

use encodeURIComponent to encode the url

For url with line jump, # , @ and special unicode in it, the following works :

var lineJump = encodeURI(String.fromCharCode(10)),
hash = "%23", arobase="%40",
tweetText = 'https://twitter.com/intent/tweet?text=Le signe chinois '+hans+' '+item.pinyin+': '+item.definition.replace(";",",")+'.'
    +lineJump+'Merci '+arobase+'Inalco_Officiel '+arobase+'CRIparis ❤️🇨🇳 '
    +lineJump+hash+'Chinois '+hash+'MOOC'
    +lineJump+'https://hanzi.cri-paris.org/',
tweetTxtUrlEncoded = tweetText+ "" +encodeURIComponent('#'+lesson+encodeURIComponent(hans));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!