【问题标题】:Tweepy - TweepError Code 89: Invalid or expired tokenTweepy - TweepError 代码 89:无效或过期的令牌
【发布时间】:2018-02-14 04:08:52
【问题描述】:

我正在尝试取消关注使用 tweepy 的人。当我早些时候使用它时,它工作得很好。但是,随后它开始出现Code 89: Invalid or expired token 错误。我访问了https://apps.twitter.com/ 页面。而且,发现我的帐户访问令牌被撤销了。但是,我再次生成了 access token 并再次尝试了一次。它取消关注另一个人,又取消关注Error Code: 89。 再次尝试,设置了 60 秒的睡眠时间,同样的事情发生了。 它取消关注一个人,然后再取消关注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)))

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    将睡眠时间从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)))
    

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 2020-05-24
      • 2016-05-24
      • 1970-01-01
      相关资源
      最近更新 更多