ttezel / twit

Twitter API Client for node (REST & Streaming API)
4.31k stars 571 forks source link

{ code: 89, message: 'Invalid or expired token.' } #204

Closed gauravgaria closed 8 years ago

gauravgaria commented 9 years ago

Not able to get the response please help asap getting this error message:- message: 'Invalid or expired token.'

code:-

                     var tweet = new Twit({
consumer_key:         tw_cKey, 
consumer_secret:      tw_cKeySecret,
 access_token:         tw_token, 
 access_token_secret:  tw_tokenSecret

});

                  tweet.get('search/tweets', function(err, data, response) {

console.log(data) res.json(data); });

dabruhce commented 9 years ago

I think this just means your access_token, access_token_secret are not valid. Are you getting/updating them correctly. You could always just run as the app only auth if you are testing stuff.

{ consumer_key: '...' , consumer_secret: '...' , app_only_auth: true }

iamstarkov commented 8 years ago

you need to get twitter api tokens

ttezel commented 8 years ago

Feel free to reopen if your credentials are valid and you're still having issues! npm update twit to get the latest version. Thanks :)

vasubits commented 6 years ago

I am getting the same error, I tried @onojatreasure solution..but it is not working...

thomasfaller commented 6 years ago

Getting the same error here on my Twitter Bot: https://github.com/thomasfaller/NodeJS-Twitter-bot/blob/master/app.js

I regenerated new tokens and made sure the permissions included 'direct messages' (it doesn't by default, but I still get the error.

Any thoughts?

thomasfaller commented 6 years ago

Hmmm found that comment in the Twitter docs:

Changes to the application permission model will only reflect in access tokens obtained after the permission model change is saved. You will need to re-negotiate existing access tokens to alter the permission level associated with each of your application's users.

So if you change permissions and save, you will need to regenerate new token keys.

vasubits commented 6 years ago

Include (- ) in access token .

Regards, Vasundhara.

On Jan 13, 2018 03:28, "Thomas Faller" notifications@github.com wrote:

Hmmm found that comment in the Twitter docs:

Changes to the application permission model will only reflect in access tokens obtained after the permission model change is saved. You will need to re-negotiate existing access tokens to alter the permission level associated with each of your application's users.

So if you change permissions and save, you will need to regenerate new token keys.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ttezel/twit/issues/204#issuecomment-357366028, or mute the thread https://github.com/notifications/unsubscribe-auth/AKbkXsvxrXukxrjQsljDD9Fpo633TTbbks5tJ9WFgaJpZM4F0dRZ .

filipppp commented 5 years ago

My Access Token is always Invalid or expired after defollowing one person with my bot, any ideas why?

Samreay commented 5 years ago

@filipppp - same issue for me. After unfollowing some users, the token becomes invalid or expired, and I have no idea why. Did you ever figure it out?

dheeman00 commented 4 years ago

Please check if you have properly placed the credentials.

Fedy-Belaid commented 3 years ago

It's all about correctly placing your credentials, keep in mind that changing permissions requires updating creds in your code!

lunaperegrina commented 2 years ago

I'm using twitter api v2 and the error {errors: [{message: 'Invalid or expired token', code: 89}]} keeps happening. I tested it with cURL and it worked fine. I have no idea what to do. I've regenerated the tokens, and it still doesn't work.

image

roe-men commented 2 years ago

i get the same errors, has anybody figured this out?

JukedByLife commented 2 years ago

If you only need to access account activity from twitter you can use the bearer token for app credentials.

https://dev.to/twitterdev/a-comprehensive-guide-for-using-the-twitter-api-v2-using-tweepy-in-python-15d9 https://developer.twitter.com/en/docs/authentication/oauth-2-0/bearer-tokens


def get_tweets(username):
    # Authorization
    client = tweepy.Client(bearer_token=os.getenv('BEARER_TOKEN'))

    query = 'from:{}'.format(username)
    tweets = client.search_recent_tweets(query=query, tweet_fields=['context_annotations', 'created_at'], max_results=10)

    temp = []

    for tweet in tweets.data:
        temp.append(tweet.text)

    return temp