DEV Community

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

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!!