Search code examples
pythontwitter

Twitter API 2018 and now


I bought a book from 2018 about Web Mining ("Mining the social web"). It starts with twitter api (I have not worked with apis in generally yet) and makes use of the twitter library from Python (I also don't know yet). The script needs some strings you need to get from twitter.

CONSUMER_KEY = ''
CONSUMER_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''

I registered a new project/app at twitter. But the strings and the names where different from the above ones:

API Key
API Key Secret
Bearer Token

Did they change since 2018? Is there a way to get the four from above: CONSUMER_KEY, etc?


Solution

  • Two things to know here:

    • the API has changed since 2018. v2 of the Twitter API is currently the default version that you get when you apply for a developer account. If you need access to v1.1 APIs which that book likely uses, you will need to request "elevated access" in the developer portal.

    • the values you want are still available, the labelling has changed slightly. CONSUMER_KEY and CONSUMER_SECRET are the same things as API Key and Key Secret, just different names. In order to get what the book calls OAUTH_TOKEN and OAUTH_TOKEN_SECRET you will need to enable OAuth 1.0A authentication for your app, and generate what the developer portal calls "access token" and secret. These are the same things as what you are seeing in the book.