1

I'm trying to use python-twitter. I'm following this tutorial.

Here is my code:

tweet = cache.get('tweet')

if not tweet:
    tweet = twitter.Api().GetUserTimeline(settings.TWITTER_USER)[0]
    tweet.date = datetime.strptime(tweet.created_at, "%a %b %d %H:%M:%S +0000 %Y")
    cache.set('tweet', tweet, settings.TWITTER_TIMEOUT)

But I'm getting next error:

Twitter.error.TwitterError: {'message': '"user_id" must be type int'}

I've set the variables like in the tutorial:

TWITTER_USER = 'CaseyNeistat'
TWITTER_TIMEOUT = 3600

Is there anything I'm doing wrong?

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
singhakash
  • 7,891
  • 6
  • 31
  • 65
  • 1
    Evidently it wants the user ID (an integer), not the name (a string). Per [the README](https://github.com/bear/python-twitter/blob/master/README.rst), if you want to pass the name use the `screen_name` keyword argument. – jonrsharpe Aug 26 '17 at 17:39
  • @jonrsharpe but in the link I shared the author passed the string for TWITTER_USER – singhakash Aug 26 '17 at 17:42
  • Maybe their article is wrong. Maybe the API changed and you're using a different version. The error message and current docs are pretty clear. – jonrsharpe Aug 26 '17 at 17:43

2 Answers2

1

The article got created about 9 years ago. So the API could changed many times since then.

Here is the signature of the function from python-twitter documentation:

GetUserTimeline(user_id=None, screen_name=None, since_id=None, max_id=None, count=None, include_rts=True, trim_user=False, exclude_replies=False)

So you want to do GetUserTimeline(screen_name=settings.TWITTER_USER)

Otherwise your string would go as user_id.

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
0

Just use screen_name as function argument. For example, GetUserTimeline(screen_name="elonmusk")