Вопрос

I'm trying to create a Twitter bot that will send a DM (direct message) to a new follower with the module tweepy. I'm not sure how I can get the latest user that has been following me. I've been reading on the Docs of tweepy but haven't found the function for the job.

Here is my code so far (not all of the code of course):

api = tweepy.API(auth)

if event:
    api.send_direct_message(twitter_user, 'Thank you for following me. Cheers!')
Это было полезно?

Решение

You can use api.followers_ids to get the most recent follower. The api docs state that the most recent follower comes first. You take take the most recent it, compare it to the last follower id you stored, and send a direct message using the user_id keyword argument if the id is unique.

Unfortunately, Twitter doesn't provide a Streaming API endpoint that notifies you about new followers, so you're stuck polling the API, unfortunately.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top