我的目标是使用tweepy (time.sleep())回复特定的tweet,回复格式是状态,最后是i的值。但我的代码不起作用,我也不知道为什么。(注:它只回复一次,不打印报告)
import tweepy
import random
import datetime
import time
def spam():
for i in range(amount):
send = str(status) + " " + str(i+1)
pause = random.randint(5,12)
auth = tweepy.OAuthHandler("xxxx", "xxxx")
auth.set_access_token("xxxx-xxxx", "xxxx")
api = tweepy.API(auth)
api.update_status(send, in_reply_to_status_id = tweetid , auto_populate_reply_metadata=True)
print("succes, pause =",pause+"s\t",datetime.datetime.now()) # for report
time.sleep(pause)
amount = int(input("amount>> "))
status = input("status>> ")
tweetid = input("id>> ")
spam()发布于 2021-11-03 08:12:01
据我所知,Twitter会屏蔽彼此相似的推文。只有一条这样的推文可以发出去。甚至我也试着改变推特之间的时间,也试图改变一两个字符,但是它还是被屏蔽了。你的代码没什么问题,是Twitter的防御机制起了作用来防止垃圾邮件。另外,如果您尝试垃圾邮件,您的API访问也可能会被阻塞。
此外,您不需要每次运行循环时都进行身份验证,只需执行一次并获得api对象,您可以在循环中使用它,如下所示
import tweepy
import random
import datetime
import time
def spam():
auth = tweepy.OAuthHandler("xxxx", "xxxx")
auth.set_access_token("xxxx-xxxx", "xxxx")
api = tweepy.API(auth)
for i in range(amount):
send = str(status) + " " + str(i+1)
pause = random.randint(5,12)
api.update_status(send, in_reply_to_status_id = tweetid , auto_populate_reply_metadata=True)
print("succes, pause =",pause+"s\t",datetime.datetime.now()) # for report
time.sleep(pause)
amount = int(input("amount>> "))
status = input("status>> ")
tweetid = input("id>> ")
spam()https://stackoverflow.com/questions/69821009
复制相似问题