Python 我的推特回复不会出现在原始状态之后
一、 我做了一个机器人,每当追随者用关键词打电话给我时,都会回复他们。然而,答复只出现在我的帐户上。收到回复的人看不到回复或收到通知Python 我的推特回复不会出现在原始状态之后,python,twitter,reply,Python,Twitter,Reply,一、 我做了一个机器人,每当追随者用关键词打电话给我时,都会回复他们。然而,答复只出现在我的帐户上。收到回复的人看不到回复或收到通知 import tweepy import random import time CONSUMER_KEY = 'xxxxx' CONSUMER_SECRET = 'xxxxx' ACCESS_KEY = 'xx-xx' ACCESS_SECRET = 'xxxx' auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUME
import tweepy
import random
import time
CONSUMER_KEY = 'xxxxx'
CONSUMER_SECRET = 'xxxxx'
ACCESS_KEY = 'xx-xx'
ACCESS_SECRET = 'xxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
max_tweets = 20
list_delirio = ['coisa escrita', 'yes']
list_isso = ['ok', 'nope']
list_acabou = ['bye', 'see you']
delirio = random.choice(list_delirio)
isso = random.choice(list_isso)
acabou = random.choice(list_acabou)
def get_id():
with open('ultimoid.txt', 'r') as f:
ultimoid = f.read()
return ultimoid
def salva_id(novo_ultimo_id):
with open('ultimoid.txt', 'w') as f:
f.write(str(novo_ultimo_id))
def responde():
ultimoid = get_id()
ids_pegos = []
time.sleep(20)
try:
for tweet in tweepy.Cursor(api.mentions_timeline, since_id=ultimoid).items(max_tweets):
ids_pegos.append(tweet.id)
user_name = tweet.user.screen_name
status = api.get_status(tweet.id)
if 'frota' in status.text.lower():
api.update_status('@' + user_name + '\n hello...', in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
elif 'hello' in status.text.lower():
api.update_status('@' + user_name + '\n wtf!', in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
elif 'delírio' in status.text.lower():
api.update_status('@' + user_name + '\n' + delirio, in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
elif 'é isso?' in status.text.lower():
api.update_status('@' + user_name + '\n' + isso, in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
time.sleep(6)
else:
api.update_status('@' + user_name + '\n' + acabou, in_reply_to_status_id=tweet.id, auto_populate_reply_metadata=True)
time.sleep(6)
salva_id(max(ids_pegos))
except Exception:
time.sleep(30)
pass
if __name__ == '__main__':
while True:
responde()
time.sleep(30)
我在试着弄明白是什么问题。我已经把
在\u reply\u to\u status\u id=tweet.id中,自动填充\u reply\u metadata=True
正如文档所述,但仍然不起作用我找到了解决方案:
行status=api.get\u status(tweet.id)
不应该在那里。所以每个status.text.lower()
都应该是tweet.text.lower()
但是最重要的是,代码必须使用字符串,而不是Id上的整数,所以每个tweet.Id
都要保留
tweet.id_str
因此,这将salva_id(max(ids_pegos))更改为salva_id(ids_pegos[0])这没有多大意义。您尚未定义
tweet.id
或user.id
,即使您定义了,它们也不会起作用。改为使用下划线。
。它不会回复此人,因为您的脚本没有识别任何人。您必须从tweetjson获取tweet\u id
和user\u id
。我建议您阅读Twitter文档,而不仅仅是Tweepy的: