Mark Biek
Mark Biek

Reputation: 150939

Retrieve all hashtags from a tweet

Is it possible using the Twitter API to retrieve a list of all hashtags present within a single tweet?

For example, let's say I have a tweet (let's say it has an ID of 12345) with the following text:

Hi. I love #stackoverflow because it's #superawesome. #fb

Is there an API call that will give me back #stackoverflow, #superawesome, & #fb when I give it an ID of 12345?

Or do I just have to parse the text of the tweet myself?

Upvotes: 2

Views: 2145

Answers (4)

trante
trante

Reputation: 33996

Although @ialphan's solution is good, if you want to sort hashtags with occurance just use this answer in similar question:
Retrieve all hashtags from a tweet in a PHP function

Upvotes: 0

ialphan
ialphan

Reputation: 1261

You can use Tweet Entities. Just include &include_entities=1.

Upvotes: 2

Yann Schwartz
Yann Schwartz

Reputation: 5994

You'll have to use a regular expression in your language of choice

   #\S+

should match any hash, beginning with # and made of a string of characters. It stops at the first space.

If you want to exclude any trailing symbol and have a letter as the last char :

#\S*\w

This expression should work in most of the regex engines I'm aware of.

Upvotes: 5

ahockley
ahockley

Reputation: 3732

The Twitter API does not have any functions specifically designed for hashtags. You'll need to parse the text on your own.

Upvotes: 1

Related Questions