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 for Google Sheets

Apipheny is an API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to unlimited API data sources, make unlimited API requests, and more. There is a 30 day free trial included.

1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install

2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.

In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.

open apipheny

Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new

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.

Note: the “app ID” is the value under “personal use script” in the screenshot above.

Step 3.) Obtain a Reddit API Token

In your command prompt window for Windows OS or a terminal for Mac OS, 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

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
Note: For Mac OS you may need to use single quotes ( ' ) instead of double quotes ( " ).
Obtaining my reddit API token
Obtaining my Reddit API token

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.

Note: If the token/key that you generate has an expiration time, you will need to complete this same process again to get a new token when the old one expires.

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, 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 of Apipheny, 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.

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.


Crypto API tutorials and more:


API Tutorials



API Knowledge

What is an API?

What is an API URL?

What are parameters?

What is an endpoint?

What is an API key/token?

What is basic authentication?

What are headers?

What is a GET request?

What is a POST request?


Sponsored by Zink Virtual Tip Jar & Rewording.io Paraphrasing Tool

Accept donations on Twitch | Accept donations on Discord | Accept donations on YouTube | Accept donations on Telegram | Accept donations on Twitter | Accept donations on TikTok | Accept donations on Instagram | Accept donations on LinkedIn | Accept donations on Facebook | Accept donations on your Website