In this tutorial, I’ll show you how to connect the Snapchat API to Google Sheets in 8 steps:
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.
Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new
Next, log in to your Snapchat account: https://ads.snapchat.com/
Then, in the menu on the left, click the Ad Accounts option, then click the “+ New Ad Account” button:
Choose the advertiser details and then click the Account Details button:
In the Account Details section, choose a name for your account, a billing type, a billing center, an account type advertising organization, a currency, and a time zone.
Then click the Create Account button:
Your ad account has been created.
You can now choose your payment method and save it by clicking the Save Payment Method button:
Your new account will then be displayed in the Ad Accounts list:
Copy and paste your ad account ID somewhere safe because you’ll need it in the next steps.
Next, click the Business Details menu item in your Snapchat ads account.
Then click the +OAuth App button in the bottom right corner:
A popup will be shown, prompting you to check the Terms and Conditions checkbox. After you click to agree to the Snapchat API terms and conditions, click the Save button:
Next, complete the App Name and Snap Redirect URI fields, then click the Save button:
Your app will then be created.
Copy and paste your Client ID and Secret to a safe location because you will need them in the next steps.
Then click the Done button once you’ve saved your Client ID and Secret:
To get your Snapchat authorization code, copy the following link, then go to your browser’s address bar, paste it, and press Enter:
https://accounts.snapchat.com/login/oauth2/authorize?client_id=your_client_id&redirect_uri=your_redirect_uri&response_type=code&scope=snapchat-marketing-api
Next, you will be asked for a list of required permissions and you will have to click the Continue button:
After you allow access to the app, your code will be displayed in the address bar, as a value for the code parameter of your API URL:
Copy and paste this code somewhere safe because you will need it in the next steps.
In your command prompt window for Windows OS or a terminal for Mac OS, write the following command to obtain your Snapchat API access token:
curl -X POST -d "grant_type=authorization_code" -d "client_id=your_client_id" -d "client_secret=your_client_secret" -d "code=your_code" -d "redirect_uri=your_redirect_uri" https://accounts.snapchat.com/login/oauth2/access_token
You’ll need to replace a few values of the command with the appropriate values:
Note: For Mac OS you may need to use single quotes ( ' ) instead of double quotes ( " ).
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.
Executing this command will return your Snapchat API access token and a Snapchat refresh access token in the response.
Copy and paste these two tokens somewhere safe, because you will need them in the next steps.
The access token will be used in API queries, whereas the refresh token will allow you to obtain a new access token when the current one expires.
If you want to obtain a new access token, just call the same command as above, but change the parameters:
In this section, I’ll show you how to browse the Snapchat API documentation to find an API endpoint URL that retrieves the specific information you need from your Snapchat account.
If you already know your API URL/endpoint, or you want to use the same example URL as us, just skip to Step 7.
To get your endpoint, first open the Snapchat API documentation page: https://developers.snapchat.com/api/docs/
The menu on the left contains an Introduction section and a list of available Snapchat API categories, each with it’s own endpoints:
If you click on an API, the page will scroll to that API’s section, which contains a list of associated endpoints for that API.
For example, if you click the “User” category, the page scrolls to the list of the available endpoints for the “User” API. In this case, there is only one endpoint: Get Authenticated User. This is the URL for that endpoint:
https://adsapi.snapchat.com/v1/me
Each endpoint’s documentation contains a short description of the endpoint’s purpose, the HTTP method used (eg. GET) and the URL for that specific endpoint, as well as a description of the available parameters for that endpoint:
All API calls to the Snapchat API should be made to this base URL:
https://adsapi.snapchat.com/v1/
All Snapchat API endpoints should be appended to this base URL.
Now, to get your Snapchat data in your Google Sheet, go back to your Google Sheet and make sure that you’ve installed the Apipheny add-on and you have it opened to the Import tab.
With the Import Tab, enter the following details into the Apipheny add-on:
Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) required by your Snapchat API endpoint. For this example, I am using the “GET” method.
API URL: In Step 6, I explained how you can find the Snapchat API endpoint that you need. Now copy your complete Snapchat API URL into the Apipheny add-on, in the field that says API URL Path (JSON / CSV), followed by any GET parameters required for your query (if applicable).
For this example, we are using the Get All Ads under an Ad Account endpoint from the Ads category, which retrieves all ads within a specified ad account. The corresponding URL for this endpoint is:
https://adsapi.snapchat.com/v1/adaccounts/ad_account_id/ads
If you’re following the same example as me, copy and paste this Snapchat API URL into the Apipheny add-on, but replace ad_account_id with your actual account ID that you copied in step 2.
Headers: In the Headers section of the Apipheny add-on, add one row with the following key and value:
Header Key: Authorization Value: Bearer your_token
Just replace your_token with the value of the token you obtained previously, in Step 5. There should be a literal space between Bearer and your_token.
Here’s what your Snapchat API request should look like when entered into the Apipheny add-on, if you’re following the same example as me:
The last step to get Snapchat data in your Google Sheet is to click the Run button at the bottom of the Apipheny add-on. Your Snapchat data will then be imported into your Google Sheets, congratulations!
That’s it! That’s how you can connect the Snapchat API to Google Sheets using Apipheny.
After making a successful request to the Snapchat API in your Google Sheet, try querying a different Snapchat API endpoint, or try using one of the more advanced features in the Apipheny add-on.
Crypto API Tutorials: