Tutorial · No code · Google Sheets

Instagram and TikTok data in Google Sheets

Paste one Apps Script file, add your key as a script property, and a HandleHaul menu fills follower counts for a list of Instagram accounts and views, likes and saves for a list of TikTok videos.

Short answer. Extensions → Apps Script, paste the script, add HANDLEHAUL_API_KEY under Project Settings → Script properties, reload the sheet, then HandleHaul → Refresh. One call per row, 1 credit each; errors (a private or missing account) show in the row instead of stopping the run.

Facts checked 2 December 2026. Prices change: follow the links before you decide.

Set it up

  • Make two sheets: Profiles with Instagram usernames (or numeric ids) in column A from row 2, and TikTok with video links or ids in column A from row 2.
  • Open Extensions → Apps Script, replace the contents of Code.gs with the script below and save.
  • Open Project Settings → Script properties → Add script property: name HANDLEHAUL_API_KEY, value your key. Script properties stay out of the sheet, so people you share the sheet with do not see the key in a cell.
  • Reload the spreadsheet. A HandleHaul menu appears; the first run asks you to authorise the script to connect to an external service.

The script

hhGet() calls the API with UrlFetchApp and muteHttpExceptions, waits for Retry-After on a 429 and returns the error code for anything else, which lands in the row.

The refresh functions read column A in one call to the sheet, fetch each row, and write all results back in one call, which keeps the run fast.

Code.gsRun: HandleHaul menu → Refresh

/**
 * HandleHaul for Google Sheets (Extensions > Apps Script, paste into Code.gs, save, reload the sheet).
 * Key: Project Settings > Script properties > add HANDLEHAUL_API_KEY = kd_live_... (or a free kd_test_ key).
 * Sheet "Profiles": Instagram usernames in column A from row 2. Sheet "TikTok": video links in column A from row 2.
 * Menu HandleHaul > Refresh ... fills the columns to the right. One call per row, 1 credit each (cache hits free).
 */
const API = 'https://api.handlehaul.com/v1';

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('HandleHaul')
    .addItem('Refresh Instagram profiles', 'refreshProfiles')
    .addItem('Refresh TikTok video stats', 'refreshTikTokVideos')
    .addToUi();
}

/** GET one endpoint. Waits and retries on 429 (Retry-After); returns { error } for anything else. */
function hhGet(path) {
  const key = PropertiesService.getScriptProperties().getProperty('HANDLEHAUL_API_KEY');
  if (!key) throw new Error('Add HANDLEHAUL_API_KEY in Project Settings > Script properties');
  for (let attempt = 0; attempt < 5; attempt++) {
    const res = UrlFetchApp.fetch(API + path, { headers: { 'X-Api-Key': key }, muteHttpExceptions: true });
    const status = res.getResponseCode();
    if (status === 429) {
      const headers = res.getHeaders();
      const wait = Number(headers['Retry-After'] || headers['retry-after']) || Math.pow(2, attempt);
      Utilities.sleep(wait * 1000);
      continue;
    }
    const body = JSON.parse(res.getContentText());
    if (status >= 400) return { error: body.error ? body.error.code : String(status) };
    return body;
  }
  return { error: 'rate_limited' };
}

/** Column A = username or numeric id. Writes B:G. */
function refreshProfiles() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Profiles');
  const last = sheet.getLastRow();
  if (last < 2) return;
  sheet.getRange(1, 2, 1, 6).setValues([['Name', 'Followers', 'Following', 'Posts', 'Verified', 'Updated']]);
  const handles = sheet.getRange(2, 1, last - 1, 1).getValues();
  const rows = handles.map(([handle]) => {
    if (!handle) return ['', '', '', '', '', ''];
    const body = hhGet('/instagram/users/' + encodeURIComponent(String(handle).trim().replace(/^@/, '')));
    if (body.error) return [body.error, '', '', '', '', new Date()];
    const p = body.data;
    return [p.full_name, p.counts.followers, p.counts.following, p.counts.posts, p.is_verified, new Date()];
  });
  sheet.getRange(2, 2, rows.length, 6).setValues(rows);
}

/** Column A = TikTok video link or id. Writes B:G. */
function refreshTikTokVideos() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('TikTok');
  const last = sheet.getLastRow();
  if (last < 2) return;
  sheet.getRange(1, 2, 1, 6).setValues([['Views', 'Likes', 'Comments', 'Shares', 'Saves', 'Updated']]);
  const links = sheet.getRange(2, 1, last - 1, 1).getValues();
  const rows = links.map(([link]) => {
    if (!link) return ['', '', '', '', '', ''];
    const body = hhGet('/tiktok/posts/' + encodeURIComponent(String(link).trim()));
    if (body.error) return [body.error, '', '', '', '', new Date()];
    const c = body.data.counts;
    return [c.views, c.likes, c.comments, c.shares, c.saves, new Date()];
  });
  sheet.getRange(2, 2, rows.length, 6).setValues(rows);
}
Tested 2026-12-02 against a local mock serving the documented API responses (retry on 429, cursor paging, a private-account error).

Refresh on a schedule

  • In Apps Script, open Triggers → Add trigger, choose refreshProfiles (or refreshTikTokVideos), event source Time-driven, and a daily or hourly timer.
  • Every refresh costs 1 credit per row. For a sheet of 200 creators refreshed daily, that is 200 calls a day; refreshing more often than the data changes only spends more.
  • Apps Script limits how long one run may take, so very long lists are better split across several sheets or triggers.

Which route to call

The setup above works with every HandleHaul route; only the URL changes. The ones people use most in automations:

  • Instagram profile: GET /v1/instagram/users/{user}. Profile by username or id.
  • Instagram followers: GET /v1/instagram/users/{user}/followers. Followers, newest first.
  • Instagram comments: GET /v1/instagram/posts/{post}/comments. Comments on a post.
  • TikTok profile: GET /v1/tiktok/users/{user}. TikTok profile: bio, verified and private flags, follower, following, like and video counts.
  • TikTok video or photo post: GET /v1/tiktok/posts/{post}. One TikTok video or photo post by id or URL.
  • TikTok transcript: GET /v1/tiktok/posts/{post}/transcript. Transcript of a TikTok video from its auto-captions.

All 49 routes, with parameters and sample responses: tutorials and the API docs.

Google Sheets: questions

Can I use a formula like =FOLLOWERS("natgeo")?
You can write one as a custom function, but Sheets recalculates formulas on its own schedule, and every recalculation is a billed call. A menu or a timed trigger keeps the number of calls under your control.
Is my API key safe in the script?
It is stored in Script properties, not in a cell, so viewers of the sheet do not see it. Anyone you give edit access to the script can read it, so share edit access with care or use a key with a monthly credit cap.

Connect Google Sheets today

One key for Instagram and TikTok. $1.40 to $0.80 per 1,000 calls; failed calls and cache hits are free.

Want to test first? Sandbox keys are free and unlimited, with sample data in the live schema.