How to import data from Reddit into Google Sheets using the Reddit API

In this tutorial, I’ll show you how to connect the Reddit API to Google Sheets in 6 steps:

  1. Install the Apipheny Add-on
  2. Create a Reddit API App
  3. Obtain a Reddit API Token
  4. Choose your Reddit API Endpoint
  5. Enter the Reddit API Request into Apipheny
  6. Run the Reddit API request in your Google Sheet

Step 1.) Install and open the Apipheny Add-on in Google Sheets

To pull data from Reddit into Google Sheets using the Reddit API without any coding, you’ll first have to install and open the Apipheny Google Sheets add-on.

Apipheny is a Google Sheets API integrator for Google Sheets that you can use to make unlimited API requests, connect to unlimited APIs, save your API requests, schedule API requests, and more. Click here for more information about Apipheny. There’s a 30-day free trial included, then it’s $19-$29/month.

1. To start the process of installing the Apipheny Google Sheets add-on, begin by opening the following link on desktop and then clicking the Install button on the page: https://gsuite.google.com/marketplace/app/apipheny/966163326746

Install the Apipheny add-on in the G Suite Marketplace
Install the Apipheny add-on in the G Suite Marketplace

2. After you’ve installed Apipheny, open a new or existing Google Sheet and then click on Add-Ons in the menu at the top of your Google Sheets. If you’ve installed Apipheny, you’ll see it as an option in the dropdown menu. Just click Apipheny > Import API to open the Apipheny sidebar in your Google Sheet.

Opening the Apipheny add-on in Google Sheets
Opening the Apipheny add-on in Google Sheets

Step 2.) Create a Reddit API App

This step is necessary to call the Reddit API. First make sure you’re logged in to your reddit account.

Then, to create a Reddit API App, first go to https://www.reddit.com/prefs/apps/ and click the “are you a developer? create an app” button:

Create a Reddit API App
Create a Reddit API App

Then complete the steps:

  • Complete the application name
  • Choose the script type for your app
  • Add a short optional description
  • Add a redirect URL

Once you have all the fields filled in, click the create app button:

Creating a Reddit App and filling out the required fields
Creating a Reddit App and filling out the required fields

You can use any valid link as the redirect URL, including https://apipheny.io/.

After you click “create app”, your app will be created:

Reddit Developed Applications
Reddit Developed Applications

On this dashboard page of your new app, you will find the app ID and secret. Copy and paste these values to a safe location because you’ll need them in the upcoming steps.

Step 3.) Obtain a Reddit API Token

In your console window, write the command below to obtain your Reddit API token:

curl -A -X -d "grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" --user "APP_ID:APP_SECRET" https://www.reddit.com/api/v1/access_token
Obtaining my reddit API token
Obtaining my reddit API token

You’ll need to fill in a few parts of the code with your own values:

  • YOUR_USERNAME and YOUR_PASSWORD are your Reddit account’s credentials
  • APP_ID and APP_SECRET are the two values you copied in the previous step, after creating your app

Executing this command will return your Reddit API access token in the response. Copy your access token and paste it somewhere safe as you will need it in the next steps.

Step 4.) Choose your Reddit API Endpoint

Every API has an endpoint. The endpoint is the latter part of the API URL that tells the API what specific data you’re looking for.

In this section, I’ll show you how to browse the Reddit API documentation to find an API endpoint URL that retrieves the information you need from Reddit. If you already know your API URL, or you want to use the same example URL as us, just skip to Step 5.

To browse the reddit API docs, first open the Reddit API documentation page by going to the following link: https://www.reddit.com/dev/api

The menu on the left of the page contains a list of methods/endpoints for the Reddit API:

Reddit API Endpoints
Reddit API Endpoints

An example method/endpoint is /api/v1/collections/subreddit_collections, used to fetch collections for a subreddit. This is the whole URL for that endpoint:

https://oauth.reddit.com/api/v1/collections/subreddit_collections

The documentation for this endpoint contains the endpoint’s HTTP method (GET) and path, a short description of the endpoint’s purpose, and the accepted parameters:

Subreddit Collections API endpoint
Subreddit Collections API endpoint

All API calls to Reddit should be made using the https://oauth.reddit.com/api/v1/ base domain. All endpoints and parameters would be appended to this endpoint.

Reddit API base domain/root URL:
https://oauth.reddit.com/api/v1/

Step 5.) Enter your Reddit API request into Apipheny

We’re in the final stretch. Go back to your Google Sheet and make sure that the Apipheny add-on is open on the “Import” tab. With the Import Tab open, enter these details into the add-on:

Method: At the top of the Apipheny add-on, select the HTTP method (GET or POST) required by your API endpoint. For this example, we are using the GET method.

API URL: In Step 4, we explained how you can find the Reddit API endpoint that you need. Now copy the complete URL into the Apipheny add-on, where it says API URL Path (JSON / CSV), followed by any GET parameters required for your query.

For this example, we are using the team.info method, that gets information about the current team. The corresponding URL for this API is:

https://oauth.reddit.com/api/v1/me

In the Headers section, add one row with the following key and value:

Headers
Key:
Authorization
Value:
Bearer <your_token>

<your_token> is the value of the token you obtained previously, in Step 3. There should be a literal space between Bearer and <your_token>. Do not include the carrots “<>” around your token.

Here’s what our Reddit API request looks like in Apipheny:

Reddit API request entered into the Apipheny add-on in Google Sheets
Reddit API request entered into the Apipheny add-on in Google Sheets

Step 6.) Run the Reddit API Request in your Google Sheet

Finally, click the Run button at the bottom of the Apipheny add-on and then the data your requesting from Reddit will be pulled into your Google Sheet, like so:

Reddit API data imported into Google Sheets using the Apipheny add-on
Reddit API data imported into Google Sheets using the Apipheny add-on

After making a successful request to the Reddit API, try querying a different Reddit endpoint (method), or try using one of the more advanced features in the Apipheny add-on, such as:

  • Save and schedule your Reddit API request in the Apipheny add-on
  • Make a POST request to the Reddit API (if available)
  • Use the custom =APIPHENY() function to call the Reddit API request inside your spreadsheet
  • Create a Reddit API request by referencing the value of a cell in the API URL with three curly braces eg. {{{Sheet1!A1}}}

If you want to pull Reddit data into Google Data Studio, just follow the same steps above and then connect your Google Sheet with your Google Data Studio report.

Apipheny Google Sheets API add-on Demo

Related Articles:

Related Posts

Leave a Comment