twitter / twurl

OAuth-enabled curl for the Twitter API
https://developer.twitter.com
MIT License
1.8k stars 301 forks source link

Authenticated successfully but getting invalid or expired token on API call #176

Closed paololazzari closed 2 years ago

paololazzari commented 2 years ago

I authenticated successfully:

$ twurl authorize --consumer-key xxx --consumer-secret xxx
Authorization successful

then, tried to run the following:

$ twurl /1.1/statuses/home_timeline.json
{"errors":[{"code":89,"message":"Invalid or expired token."}]}
andypiper commented 2 years ago

Just to clarify, and we don't need to see the whole process, but can you confirm that when you ran twurl authorize, you then went through a PIN-based authentication process involving the web browser and the terminal? And that twurl accounts shows you have a default account and that your .twurlrc file contains account secret and token (please do not share these)

andypiper commented 2 years ago

Additionally, if you have a new Twitter Developer Account, do you have access to the v1.1 API (elevated access)

paololazzari commented 2 years ago

@andypiper Thank you for your reply. It looks like the culprit was the .twurlrc file; for some reason the default_profile was pointing to the wrong profile (one which had consumer_key and consumer_secret different that what I had used to authenticate).

As soon as I changed the default profile the API call worked as expected.

andypiper commented 2 years ago

FWIW you can use twurl accounts and twurl set default to fix that if you don't want to edit the hidden file manually. Good to know things are working!