I’m working on a basic twitter app, using the Tweepy python library, to unfollow people who don’t follow me. Yesterday I had it running and it was working fine. Today it keeps failing: as soon as I run the program, I get an error message: Invalid or Expired Token, code 89. If I go to my Twitter app page in dev.twitter.com, the app is there and hasn’t been suspended, but on the Keys and Access Tokens tab, it doesn’t have any access token, and says I need to create one. If I create one, and run the program again, the same error happens And If I got back to the app dashboard, same thing, it says I don’t have any access tokens and I need to create some, and so on.
the source code is below. I’ve tried googling and searching here and can’t find a solution. Any help greatly appreciated.
import tweepy, time, sys
CONSUMER_KEY = "..."
CONSUMER_SECRET = "..."
ACCESS_KEY = "...-..."
ACCESS_SECRET = "..."
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
followers = api.followers_ids('@...')
friends = api.friends_ids('@...')
for f in friends:
if f not in followers:
print "Unfollow {0}?".format(api.get_user(f).screen_name)
if raw_input("Y/N?") == 'y' or 'Y':
api.destroy_friendship(f)