当我运行以下代码时,我不断收到“需要身份验证”错误:
import tweepy
import time
credentials = [
{
"consumer_key": 'xxx',
"consumer_secret": 'xxx',
"access_token": 'xxx',
"access_token_secret": 'xxx'
},
{
"consumer_key": 'xxx',
"consumer_secret": 'xxx',
"access_token": 'xxx',
"access_token_secret": 'xxx'
},
{
"consumer_key": 'xxx',
"consumer_secret": 'xxx',
"access_token": 'xxx',
"access_token_secret": 'xxx'
}
]
numofAccs = 3
username = "xxx"
apis = [tweepy.API(tweepy.OAuthHandler(c["consumer_key"], c["consumer_secret"]).set_access_token(c["access_token"], c["access_token_secret"])) for c in credentials]
latest_retweet_ids = [None] * numofAccs
while True:
try:
# Get the latest tweet from the specified user
latest_tweet = apis[0].user_timeline(screen_name=username, count=1)[0]
# If this is a new tweet, retweet it from each account and update the latest_retweet_id variables
if latest_tweet.id not in latest_retweet_ids:
for api in apis:
time.sleep(10) #Delay for 10s on purpose
api.retweet(latest_tweet.id)
time.sleep(10) #Delay for 10s on purpose
api.create_favorite(latest_tweet.id)
latest_retweet_ids = [latest_tweet.id] * numofAccs
print(f"Retweeted: {latest_tweet.text} from all " + numofAccs + " accounts.")
else:
print("No new tweets to retweet.")
except tweepy.errors.TweepyException as e:
print(e)
time.sleep(60) # Wait for 1 minute before checking again (Don't want to spam)
与单引号或双引号有关吗?我都试过了,但都没有用。可能与我设置字典的方式有关吗?任何细节都会很棒