Tweepy - TweepError代码89:令牌无效或过期

时间:2017-09-05 19:34:00

标签: python twitter tweepy

我试图使用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)))

1 个答案:

答案 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)))