Skip to main content

Twitter

"Twitter, Inc. is an American communications company based in San Francisco, California. The company operates the microblogging and social networking service Twitter. It previously operated the Vine short video app and Periscope livestreaming service."

Configuration​

Getting Twitter OAuth credentials​

Start by accessing or creating a Twitter account.

If you do not already have a Client Id and Client Secret, you will first need to create them. Start by creating a project.

Note: If you don't already have a developer enabled account you will be required to fill in some additional organization and usage information along with the developer agreement and policy.

Once you have created a project in the Twitter developer portal, you will be required to provide an App name click on the "Next" button, then "Keys & Tokens" and note your Client Id (API Key) and Client Secret (API Key Secret) for the next step.

NOTE: The Client Id and Client Secret will no longer be visible after it is shown for the first time so be sure to temporarily copy it for the next step.

Configuring Twitter OAuth Credentials in crul​

Navigate to the credentials page in crul (top right corner menu -> credentials).

Click the "create" button.

Select "OAuth" from the type dropdown, then select "Twitter" from the provider dropdown.

Copy the Client Id (API Key) into the Client Id credentials form entry. Then copy the Client Secret (API Key Secret) into the Client Secret credentials form entry.

Test the credential by running the following query. You should see a populated token.access_token column in the results.

oauth --credential "twitter"

Example queries​

Auth​

oauth
--auth.tokenHost "https://api.twitter.com"
--auth.tokenPath "/oauth2/token"
--client.id "${API Key}"
--client.secret "${API Key Secret}"
--grant "clientcred"

These examples use the endpoints described in the Twitter API v2 reference. Note: The root scheme/host for the Twitter API is https://api.twitter.com

Example 1:​

Tweets from the last seven days that match a search query NASA.

oauth --credential "twitter"
|| api get https://api.twitter.com/2/tweets/search/recent?query=NASA&tweet.fields=created_at,author_id --token.access_token "$token.access_token$"
|| normalize data
|| table id created_at text author_id

Example 2:​

The Twitter usernames from Tweets over the last seven days that match a search query NASA.

oauth --credential "twitter"
|| api get https://api.twitter.com/2/tweets/search/recent?query=NASA&tweet.fields=created_at,author_id --token.access_token "$token.access_token$"
|| normalize data
|| api get https://api.twitter.com/2/users/$author_id$?user.fields=verified,location --token.access_token "$token.access_token$"
|| table data.username data.verified data.location