DEV Community

Aditya from Kaapi
Aditya from Kaapi

Posted on

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

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?

Top comments (4)

Collapse
 
dara_tobi profile image
Dara • Edited

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!

Collapse
 
adityarao310 profile image
Aditya from Kaapi • Edited

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

Collapse
 
dara_tobi profile image
Dara

You're very welcome!!

Collapse
 
ionline247 profile image
Matthew Bramer

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.