Python tweepy找到搜索用户

时间:2015-08-13 17:51:14

标签: python twitter tweepy

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)

简而言之,我正在尝试找到一个字符串,然后将该字符串转发到我的Feed并跟随该人。

我的问题是如何通过搜索字符串找到Twitter ID?

我一直在四处搜索,但在Python上找不到太多的例子。

1 个答案:

答案 0 :(得分:1)

如果您想要使用状态ID tweet_id发送推文的用户的用户ID。 使用此

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