Use Twitter as a data source

Resources

Data Source Type: REST/URL
Authentication: OAuthToken Authentication
Sample Query:

Returns 50 most recent mentions including favourites, retweets, and mentions.

https://api.twitter.com/1.1/statuses/mentions_timeline.json?count=50
API Documentation: Twitter REST API Docs
API Explorer: Twitter's API Explorer
Date Ranges: Klipfolio Date Ranges

Step-by-Step

Creating a data source using Twitter

To create a data source using Twitter data, you need to accomplish 5 tasks:

  • Start the data source creation process.
  • Authenticate with Twitter.
  • Use the API Explorer to write a query.
  • Enter the query in Klipfolio. 
  • Use Klipfolio to adjust the query for your dashboard.

Note: This guide assumes that you already have an active Twitter account.

Step 1: Start the data source creation process

To create a data source using Twitter, go to the Connector Gallery page in Klipfolio and select the Twitter connector.

Step 2: Authenticate with Twitter

  1. Click the Connect new account link.
  2. Enter your Twitter username and password when prompted.
  3. Click the Authorize App button to allow Klipfolio to access your Twitter account.

Step 3: Use the Twitter API Explorer to write a query

In this section, you will work with Twitter's API Explorer to construct a URL.

  1. Navigate to the following URL in a new browser window or tab: https://dev.twitter.com/console
  2. From the Authentication menu, use the drop-down menu to select OAuth 1, to authorize Twitter to retrieve data for your account.
  3. Sign in with Twitter and click the Authorize app button to authorize Twitter's API to use your account.
  4. From the Service drop down menu, select a service to find a Query URL. For example, https://api.twitter.com/1.1.
  5. Select an API method.  For example, mentions_timeline.json.
  6. Click the Send button to test the Query URL.
  7. Optional: Use tabs within the explorer to provide additional parameters to the Query URL

Step 4: Enter the query in Klipfolio 

Now you'll need to bring the query you wrote with the Query Explorer into Klipfolio.

  1. In the Twitter API explorer, Request URL section, select the URL in the text field. For example, https://api.twitter.com/1.1/statuses/mentions_timeline.json.
  2. Copy the URL to your clipboard.
  3. Return to Klipfolio.
  4. Paste the URL in the URL field on the New Data Source page.

Step 5: Edit the query date ranges and save

Many Klips that use Twitter data need a date range that is dynamic (for example, past 30 days). In this section, we're going to change the query from a fixed range to a dynamic one.

  1. Add a ? to the end of the URL.
  2. Enter start-date={date.last30Days} at the end of your Query URL (after the ?).
  3. Enter &end-date={date.today} at the end of your Query URL (after the start-date parameter).
  4. At Data Format, use the drop-down menu to select JSON.
  5. Click the Get Resource button.
  6. Click the Continue button once you verify you have retrieved the correct data to Save your data source.

This may override other parameters in your Query URL such as count=50. To resolve this issue, delete the parameter. The Query URL will return all the data within the period specified. If you modify the sample query provided above using a date range, this is what it will look like:
https://api.twitter.com/1.1/statuses/mentions_timeline.json?start-date={date.last30Days}&end-date={date.today}

Common date range expressions:

Query examples

The following are some commonly used queries when retrieving data from Twitter.

Request Query
Returns tweets for a user named "TwitterUser" in the last 30 days . https://api.twitter.com/1.1/search/tweets.json?q=%40TwitterUser&start-date={date.last30Days}&end-date={date.today}

Note: This query uses %40 for the @ symbol.

 

Learn More

Now that you have your data, here are some ideas on how to use it:

Did you have trouble with the material in this article?

These articles may help: