Tutorial / Authenticating with the Twitter API for enterprise

Overview of the different authentication methods

Three different authentication methods exist to access the Twitter enterprise APIs. Each of these methods is described below.

  1. HTTP Basic Authentication
  2. OAuth 1.0a (user context)
  3. OAuth 2.0 Bearer Token (application-only)

 

HTTP Basic Authentication

How it works

Most of Twitter’s Enterprise APIs require HTTP Basic Authentication. This consists of a valid email address and password combination passed as an authorization header for each API request.

Prerequisite

Access to the enterprise console: https://console.gnip.com/.

You will need

Username and password. This username and password combination is the same login credentials (email address and password) used to log in to the enterprise console.

 

OAuth 1.0a (user context)

How it works

OAuth 1.0a (sometimes also referred to as “user context authentication”) allows you to make API requests on behalf of a Twitter user. This authentication method allows you to send your developer App’s Consumer Keys (API Key and Secret), alongside a set of user access Tokens (Access Token and Secret), as part of the authorization header in the API request. 

While the Consumer Keys give the API context about the developer App that is sending a request, the Access Tokens provide context about the Twitter user on behalf of whom the App is sending the request. 

All write actions and all reading of protected data using the Twitter API require OAuth 1.0a, and the Access Tokens must belong to the owning user. For example, in the case of posting a Tweet, the Access Tokens must belong to the user on behalf of whom you are posting the Tweet. Similarly, if you are accessing private engagement metrics with the Engagement API, the Access Tokens must belong to the user who owns the Tweet(s) and related protected data. 

If the user behind a request is yourself (in other words, the Twitter account that owns the developer App) the required Access Tokens can be generated directly from within the developer portal (under the “Keys and tokens” tab for your developer App).

For all other Twitter accounts, users must first authorize your developer App for access. A user can grant your developer App access by undergoing the 3-legged OAuth flow, which in turn allows you to obtain the user’s Access Tokens. You can then use these Access Tokens to authenticate your request and make a request on behalf of the user.

Information on how to obtain a user’s Access Tokens is included in the article OAuth 1.0a: how to obtain a user’s access tokens

Information on how to authorize a request using OAuth 1.0a can be found in our documentation.

Prerequisite

 

You will need

1. Consumer Keys (API Key and Secret).

  • These can be generated in your developer portal, under the “Keys and tokens” tab for your developer App.

 

2. User Access Tokens (Access Token and Secret). 

  • If you are making a request on behalf of your own account, these can be generated in your developer portal, under the “Keys and tokens” tab for your developer App.

  • If you are making a request on behalf of another user, you can obtain these Access Tokens via the 3-legged OAuth flow. You can read more about how to do this below: OAuth 1.0a: how to obtain a user's access tokens.

     

OAuth 2.0 Bearer Token (application-only)

How it works

OAuth 2.0 Bearer Token allows you to make API requests on behalf of your Twitter developer App. This authentication method is also sometimes referred to as “application-only authentication” because the credentials you send as part of the request give the API context about your developer App. Compared to OAuth 1.0a user context authentication, OAuth 2.0 Bearer Token does not involve any Twitter user(s). This authentication is typically used for read-only access to publicly available information (for example, accessing public Tweets).

Prerequisite

 

You will need

Consumer Keys (API Key and Secret) or a Bearer Token. These can be generated in your developer portal, under the “Keys and tokens” tab for your developer App.

 

 

 

Go to the next article - Which authentication method to use for each API

Go back to the tutorial homepage - Authenticating with the Twitter API for enterprise

 

 

Ready to build your solution?

Apply for developer access to get started