Python tweepy 查找用户搜索

Python tweepy find user of search

import time
import tweepy

from auth import consumer_key, consumer_secret, access_token, access_token_secret

string_to_search = 'new car ideas'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

past_status_ids = set()

while True:
    tweets = api.search(q=string_to_search)
tweet_id_list = set([tweet.id for tweet in tweets])
new_tweet_ids = tweet_id_list - past_status_ids
past_status_ids = tweet_id_list | past_status_ids



for tweet_id in new_tweet_ids:
    print "Retweeting " + str(tweet_id)
    api.retweet(tweet_id)
    #username = tweets.user.screen_name
    #api.create_friendship(username)
    #print "Followed " + str(username)
    limits = api.rate_limit_status()
    remain_search_limits = limits['resources']['search']['/search/tweets']['remaining']
    print("Limit left is " + str(remain_search_limits))
    print("")
    time.sleep(150)

简而言之,我试图找到一个字符串,然后在我的提要上转发该字符串并关注那个人。

我的问题是如何找到 Twitter ID 以通过搜索字符串关注他们?

我一直在四处搜索,但在 Python tweepy 中找不到太多关于此的示例。

如果您想要发布状态 ID tweet_id 的推文的用户的用户 ID。 使用这个

tweet = api.get_status(tweet_id)
user_id = tweet.user.id
# Now follow that user
api.create_friendship(user_id)