However, the Twitter policies do not allow us to return the full Tweet metadata in our API (e.g. the text of tweets), like we do in our applications.

Because of this, the API will return no other metadata than the ID and URL of the Tweets.

This guide explains how to fetch the metadata of relevant Tweets found by the Mention API.

Overview

Fetching the metadata of relevant Tweets found by the Mention API can be done by using the official Twitter API. In particular, the Twitter API has a endpoint called statuses/lookup that returns the metadata of the Tweet whose IDs that are passed to it.

Register a Twitter API application

Once the app has been created, go to the "Keys and Access Tokens" section, and copy the following information:

Consumer Key (API Key)

Consumer Secret (API Secret)

Then, create an access token by clicking on the "Create my access token" button at the bottom of the page. Copy the following information:

Access Token

Access Token Secret

Accessing the Twitter API

Before this step, make sure that you retrieved the following information from the previous step:

Consumer Key (API Key)

Consumer Secret (API Secret)

Access Token

Access Token Secret

The Twitter API is a simple REST API, however it requires users to authenticate themselves by using the OAuth 1.0A protocol. Unlike OAuth 2, this version of the protocol requires a library to be used easily and safely.

Most languages have a library with good OAuth 1.0A support. Here are a few:

Note: The endpoint is limited to 180 calls per 15 minute windows, and can fetch up to 100 tweets per call. We recommend to batch calls to the endpoint as much as possible in order to avoid calling it with less than 100 tweets. Caching tweets locally can also reduce the number of calls to the endpoint.

Examples

NodeJS

Note: This code requires the oauth npm package, which can be installed with the following command: