loading...

Is there a way to programmatically get Twitter user name if I know website URL of the user?

twitter logo github logo ・1 min read

I have a bunch of website URLs. Most business accounts mention their websites in their Twitter bio. I would like to get Twitter usernames/handles of those websites

e.g. user https://twitter.com/adityarao310 mentions https://timewise.how/ in their Twitter bio. I know Timewise.how --> can I get @adityarao310 ? I have 300 such website URLs

  • I have tried going through the Twitter standard search but it doesnt work for searching through bio

  • I also thought about doing wget and then grep to get twitter.com/xxxx in the website pages because I am assuming that most website mention their social links at the footers usually. But I am unable to figure the right regex for this

Can someone please point me in the right direction?

twitter logo DISCUSS (4)
markdown guide
 

According to this article searchenginepeople.com/blog/twitte..., your best bet is to use a Google advanced search query.

The google advanced search query that has consistently returned the official Twitter handle of a URL is:
site:twitter.com -inurl:status {URL} e.g. site:twitter.com -inurl:status timewise.how returns a link to the profile of @adityarao310 as the first search result.

Since you want to get this programmatically, you need to create a Google custom search engine (CSE) (see here: developers.google.com/custom-searc...) and make an API call (see here: developers.google.com/custom-searc...) to your CSE, then pick out the first item from the response in your API call (using the first item in the response might not always be accurate, but it seems to be your best bet)

A list of fields in the first item in the response from the custom search API for when I tried this with your sample URL included

Good luck!

 

This is freaking fab and exactly what I was looking for! Solved my problem completely
Thanks a lot for taking out the time to do this

 
 

It's not clear if you have the Twitter handle and are looking for the website in the profile, or have the website and are looking for the twitter handle.

If you have the website, you can use a search engine and get some results: "timewise.how" site:twitter.com

If you have the twitter handle, you can use the API to get a user object that contains the website url.

Classic DEV Post from Jun 15 '19

What are your favourite resources for beginners?

What resources would you give a new team member who is also starting their first tech job?

Aditya Rao profile image
Happiness of pursuit. I self learned how to code in 2019.

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❀️