【发布时间】:2018-06-02 06:30:53
【问题描述】:
我正在尝试用 tweepy 回复某些推文,而我的回复包含一张图片。 twt 变量保存我要回复的推文。 这是我目前正在做的事情:
# -*- coding: utf-8 -*-
import tweepy, time, random
CONSUMER_KEY = 'XXXX'
CONSUMER_SECRET = 'XXXX'
ACCESS_KEY = 'XXXX'
ACCESS_SECRET = 'XXXX'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
query = ['aaa', 'bbb', 'ccc']
t0 = time.time()
count = 0
last_count = 0
f = open('last_replied.txt')
last_replied = int(f.readline().strip())
f.close()
print('starting time:', time.strftime('%X'))
while True:
if count > last_count:
print(time.strftime('%X'), ':', count, 'replies')
last_count = count
for i in range(3):
twts = api.search(query[i], since_id=last_replied)
if len(twts)>0:
for twt in twts:
sid = twt.id
sn = twt.user.screen_name
stat = "lalala" + "@" + sn
api.update_with_media('oscar1.gif',status=stat,in_reply_to_status_id=sid)
count += 1
last_replied = twt.id
f = open('last_replied.txt','w')
f.write(str(last_replied))
f.close()
pause = random.randint(50,90)
time.sleep(pause)
我的推文被发布,但不是作为对原始推文的回复 (twt)。相反,它只是作为新的、独立的推文发布。
但是,当我使用 update_status 代替上面的 update_with_media 时,例如:
api.update_status(status=stat,in_reply_to_status_id=sid)
我的新推文确实会作为对原始推文的回复发布 (twt)。
我错过了什么?
谢谢
【问题讨论】:
-
这里是用 api.update_with_media 回复推文的一些代码,并且工作正常,也许看看一些代码对你有帮助:) github.com/Soben713/Twizhoosh/blob/master/scripts/…
-
@Mohammadalibaghershemirani 我相信你正在使用其他模块,而不是像我这样的 tweepy