簡體   English   中英

Python tweepy-搜索關鍵字,然后回復

[英]Python tweepy - search keyword then reply

我要執行以下操作:

1)搜索一個單詞(例如:“ dog”)2)回復(提及)那些用戶如何用“ dog”這個單詞發布推文

這是我走了多遠:

import tweepy

consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''

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

api = tweepy.API(auth)

tweetId = tweet['results'][0]['id']

api.update_status('My status update',tweetId)

我收到一條錯誤消息“未定義推文”。

我不明白,該從哪里獲得tweetId?

謝謝你的幫助 :-)

您的“ tweet”變量沒有任何價值,因此您嘗試從尚未分配的內容中獲取tweetId。 使用以下API調用之一http://docs.tweepy.org/en/v3.2.0/getting_started.html ,您實際上應該能夠檢索推文。

例如,訪問用戶主頁上的推文:

public_tweets = api.home_timeline()
for tweet in public_tweets:
    print tweet.text

然后,您應該自己進行一些研究,以嘗試找出如何搜索此數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM