Hi
I am trying to fetch statuses from realdonaldtrump Twitter account using a simple code:

import twitter
token = 'XX'
token_key = 'XX'
con_secret = 'XX'
con_secret_key = 'XX'
api = twitter.Api(consumer_key=token,
                  consumer_secret=token_key,
                  access_token_key=con_secret,
                  access_token_secret=con_secret_key)
user = '25073877'
statuses = api.GetUserTimeline(user)
for s in statuses:
   print(s.text)

This is what I am getting back when running on terminal.

None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None

I looks like it fetches an array with blanks. When I try to fetch data twitter account with no tweets, I get zero results. That’s why I guess the connection works but the data I get back are wrong.

Any idea what am I doing wrong?

1 Like

what library is that? maybe there are some more parameters you need to set. This depends on the library itself, but the actual endpoint has these: Overview | Docs | Twitter Developer Platform

and you will also have to paginate results, like this Working with timelines | Docs | Twitter Developer Platform

How that’s implemented by the library you’re using depends entirely on how it was made so i’d look up the documentation for that.

1 Like

Hi Igor,

thank you. This is Python-Twitter library (cannot post links for some reason) and the code corresponds with the examples the authors themselves published.

So my take was there is something wrong with my dev account rather than the code. Anyways, can I check somehow whether there was actual request from my account to twitter?

Cheers,
Tomas.

1 Like

I think the issue is in how statuses = api.GetUserTimeline(user) is called.

You have

user = '25073877'
statuses = api.GetUserTimeline(user)

which i think should be more like:

user = 25073877
statuses = api.GetUserTimeline(user_id=user)

Check out python-twitter/get_all_user_tweets.py at master · bear/python-twitter · GitHub that example looks more complete (it sets screen_name instead of user_id but using either one should be fine, just make sure to send user_id as an integer not a string)

1 Like

Thank you Igor. I think there will be something else there. I just followed your suggestion but get the same results. Anyways, thanks for your comments.

1 Like

Could you try passing the parameters as follow:

statuses = api.GetUserTimeline(['user_id' => '25073877', 'count' => 5, 'format' => 'json']);

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.