Search code examples
pythontwittertweepy

tweepy api.me() not returning user objects of friends


So from the tweepy documentation, I should be able to user api.me() to get a list of friends a user is following: http://pythonhosted.org/tweepy/html/api.html#user-methods First,I did usual OAuth dance:

import tweepy
consumer_token='#####'
consumer_secret='$$$$$'
access_token='&&&&&'
access_token_secret='****'
auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth)
daysinn_friends=api.me('DaysInnCanada')

And then python gave me an error saying:

Traceback (most recent call last):
File "<pyshell#40>", line 1, in <module>
daysinn_friend=api.me('DaysInnCanada')
TypeError: me() takes exactly 1 argument (2 given)

But I didn't pass 2 arguments into me(), the only argument was the screen_name. I'm really confused and couldn't figure it out. Thanks


Solution

  • The "extra" parameter that's confusing you is the Python self parameter. I've already written a long explanation of self in https://stackoverflow.com/a/16259484/2314532, so instead of repeating it I'll just point you to that answer. If after reading that you still don't understand what's going on, let me know and I'll see if I can explain further.

    Also, looking at the API documentation for tweepy, me() is supposed to take no parameters, and you're passing it one. From glancing at your code, I suspect what you really meant to do is call api.followers("DaysInnCanada"). Or maybe api.get_user("DaysInnCanada"), but I suspect you meant to use followers.