How do you include hashtags within Twitter share link text?

Splendiferous picture Splendiferous · Feb 3, 2012 · Viewed 58.2k times · Source

I'm writing a site with a custom tweet button that uses the www.twitter.com/share function, however the problem I am having is including hash '#' characters within the tweet text.

For example:

http://www.twitter.com/share?url=www.example.com&text=I+am+eating+#branstonpickel+right+now
The tweet text comes out as 'I am eating' and omits the hash and everything after.

I had a quick look on the Twitter forums and learnt the hash '#' character cannot be part of the share url.
On https://dev.twitter.com/discussions/512#comment-877 it was said that:

Hashes are special characters in the URL (they identify document fragments) so they, and anything following, does not get sent the server.

and

you need to URLEncode it, so use %23

When I tried the 2nd point in my test link:

www.twitter.com/share?url=www.example.com&text=I+am+eating+%23branstonpickel+right+now
The tweet text came out as 'I am eating %23branstonpickel right now' literally including %23 instead of converting it to a hash.

Sorry for the waffely question, but does anyone know what it is I'm doing wrong?
Any feedback would be greatly appreciated :)

Answer

adamb0mb picture adamb0mb · Dec 12, 2012

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.