Grant Brown
Grant Brown

Reputation: 641

Tweepy exists_friendship doesn't exist?

This isn't all my code but its the problem part.

api = tweepy.API(auth)
x = api.exists_friendship(user_a, user_b)
print x

returns

x = api.exists_friendships(user_a, user_b)
AttributeError: 'API' object has no attribute 'exists_friendships'

anyone know why? Would really help! Thanks.

Upvotes: 1

Views: 2774

Answers (2)

msonsona
msonsona

Reputation: 1311

You can use the lookup_friendships method:

# Lookup in blocks of 100 users
relationships = api.lookup_friendships(screen_names=users[0:100])
for relationship in relationships:
    if not relationship.is_following:
        print("User is not following", relationship.screen_name)
        api.create_friendship(relationship.screen_name)

Upvotes: 0

bosnjak
bosnjak

Reputation: 8614

You are getting the error because there is no such method in the api. You are most likely following and older tutorial, and I think that even the official documentation is not updated yet, even though this was changed more than a year ago...

The Twitter API changed in version 1.1 and added authentication as a requirement. This also caused the change to the relationship lookup endpoint, and thus the Tweepy API changed.

You can find more information about the new Twitter API here: https://dev.twitter.com/rest/reference/get/friendships/lookup

The new function that Tweepy provides for this is: lookup_friendships.

Upvotes: 5

Related Questions