How to access the tweepy entities expanded_url and why some are not available as object properties

Viewed 115

I'm trying to get my head around tweepy and extracting data about followers in particular.

I'm authenticated, queried twitter for details of my own followers and can print out details about them using

Followers = AboutMe.followers
for follows in Followers():
    print(follows.id, "is user ID for ", follows.screen_name, " from ", follows.location, follows.url)

When I execute that I get urls like https://t.co/[uniquestring] instead of FQDMs which I was hoping for

There is a property/entity called expanded_url but its not accessible as a object property. Why is that? and how do I access it if its embedded in lower levels of json entities

I provide a sample of the output if I print(follows.entities)

{'url': {'urls': [{'url': 'https://t.co/[string]', 'expanded_url': 'http://www.fqdm', 'display_url': 'domain.tld', 'indices': [0, 23]}]}, 'description': {'urls': []}}

1 Answers

As per the documentation and the output of print(follows.entities) the following code answers your question to get FQDN for followers:

Followers = AboutMe.followers
for follows in Followers():
    print(follows.id, "is user ID for ", follows.screen_name, " from ", follows.location, follows.entities.url.urls[0].expanded_url)

You might also want to handle the case when user has no url.

Related