How To Get Hash Tags, Shortened URLs, @Replies From a Twitter Tweet

How To Get Hash Tags, Shortened URLs, @Replies From a Twitter Tweet

For most Twitter users who use the site for sharing thoughts for the sake of sharing, knowing how to get hash tags, shortened URLs, @replies from a Twitter tweet is not that important. But if you are a site owner who wants to share tweets and the contents of those tweets on your site or on an iOS application, this is something that you ought to learn.

Most people share tweets via websites by just taking a screenshot of the tweet and posting it as an image. That will be enough if you just want to share your thoughts or other people’s tweets. But if you want to make the tweet actionable, say, make the shortened URLs clickable, you need to know how to get hash tags, shortened URLs, @replies from a Twitter tweet.

Getting Has Tags, Shortened URLs and @Replies from Twitter Tweets

There are a number of ways on how to get these tweet elements and make them actionable or clickable on a webpage. The important thing about this is knowing the fastest way so that you can parse these elements easily, especially when you consume bulk tweets on a regular basis.

Here are some ways on how to get hash tags, shortened URLs, @replies from a Twitter tweet and make them work on your own site.

  • Regular Expressions

Using RegEx, you can make tweets be hyperlinked instead of appearing as plain text. Execute the function to make the tweets actionable:

//Twitter Parsers

String.prototype.parseURL = function() {

return this.replace(/[A-Za-z]+://[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&~?/.=]+/g, function(url) {

return url.link(url);

});

};

String.prototype.parseUsername = function() {

return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {

var username = u.replace(“@”,””)

return u.link(“https://twitter.com/”+username);

});

};

String.prototype.parseHashtag = function() {

return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) {

var tag = t.replace(“#”,”%23″)

return t.link(“https://twitter.com/search?q=”+tag+”&src=hash”);

});

};

 

This function will enable the tweet’s links to be clickable on Android, iOS and websites.

  • iOS

To know how to get hash tags, shortened URLs, @replies from a Twitter tweet via iOS, you should know the right protocol, and it is the same as the one mentioned above.

You can also do this via iOS just by loading the tweet on UIWebView with HTML and calling the function above through the body tag onLoad method.

If you have received the tweet via text message, you can execute this function to make it workable on RegEx:

tweetText = tweetText.parseURL().parseUsername().parseHashtag();

This will enable you to click on the links of the tweet as this function will make the text message tweet be converted into a hyperlinked text instead of a plain text message tweet.

Because you now know how to get hash tags, shortened URLs, @replies from a Twitter tweet, which is usable in various interfaces that enable Javascript protocol, you can use the tweets that you have converted into hyperlinked tweets on your site and other interface such as iOS and Adnroid.

This is great because you will be able to not share your clickable tweets on your website but also on platforms that are accessed by iOS and Android devices.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: