0

I'm new to python. I am using the libray called python-twitter to grab data of my own twitter account

Here is my code (twitter-test.py)

import twitter

api = twitter.Api(consumer_key="xxxxxxxx",
                  consumer_secret="xxxxxxxxxx",
                  access_token_key="xxxxxx-xxxx",
                  access_token_secret="xxxxxxx",
                  sleep_on_rate_limit=True)
follower = api.GetFollowers()
print(follower)

then i run python3 twitter-test.py Here is the result.

[User(ID=xxxxxxxxx, ScreenName=xxxxxxx), User(ID=xxxxxxxxx, ScreenName=xxxxxxx), User(ID=xxxxxxxxx, ScreenName=xxxxxxx), .......]

The api is call successfully.

Now I want to save the result:

import json

{ The code same as before }

json.dumps(follower)
TypeError: Object of type User is not JSON serializable

Then I tried to loop the result using for x in follower:

but x[0] x['ID'] x.ID all return error:

TypeError: 'User' object is not subscriptable

How can I extract the data from User Object ?

2
  • it returns you list of tuples so just try for x in follower: x[0] # x[1] Commented Jun 15, 2020 at 7:31
  • @Sibyl TypeError: 'User' object is not subscriptable Commented Jun 15, 2020 at 7:47

1 Answer 1

1

this is works fine for me

GetFollowers() function returns an user object in a list you can find object details here

followers = api.GetFollowers()
for follower in followers:
    print(follower.created_at)
    print(follower.name)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.