我试图使用tweepy取消关注用户。我早些时候使用它时效果很好。但是,它开始出现Code 89: Invalid or expired token
错误。我访问了https://apps.twitter.com/页面。并且,发现,我的帐户访问令牌被撤销。但是,我再次生成访问令牌并再次尝试。它再次取消了另一个人Error Code: 89
。
再次尝试,设置60s的时间睡眠,同样的事情发生了。
它取消关注一个人然后再次Error Code: 89
,并且再次自动撤销访问令牌。
name = api.me().name
friendlist = api.friends_ids(name)
followers = api.followers_ids(name)
with open('unfollowed.csv', "w") as f:
for suspect in friendlist:
if suspect not in followers and suspect not in protected_friends:
try:
txt = str(suspect)+", " +"https://twitter.com/%s" % api.get_user(suspect).screen_name
print(txt)
f.write(txt+'\n')
api.destroy_friendship(suspect)
time.sleep(60)
except Exception as e:
print(e)
time.sleep(60)
continue
print("Now, Following, %d(%d)" % (api.me().friends_count, len(friendlist)))
答案 0 :(得分:0)
将睡眠时间从60
增加到100
就可以了。显然,修改后的脚本需要更多时间来执行。但是,它有效...
name = api.me().name
friendlist = api.friends_ids(name)
followers = api.followers_ids(name)
with open('unfollowed.csv', "w") as f:
for suspect in friendlist:
if suspect not in followers and suspect not in protected_friends:
try:
txt = str(suspect)+", " +"https://twitter.com/%s" % api.get_user(suspect).screen_name
print(txt)
f.write(txt+'\n')
api.destroy_friendship(suspect)
time.sleep(100)
except Exception as e:
print(e)
time.sleep(120)
continue
print("Now, Following, %d(%d)" % (api.me().friends_count, len(friendlist)))