Tutorials
Import Public Instagram Data to Google Sheets Using Apps Script
Pull public Instagram follower counts, profile metadata, and snapshot timestamps into Google Sheets without paying $30 to $99 per month for connector add-ons. This tutorial walks through instagram-google-sheets.js using native Google Apps Script, Script Properties credential storage, formula-safe escaping, and time-driven triggers at $0.003 per lookup.
- Zero add-on subscriptions: Runs natively in Google Apps Script (
UrlFetchApp+SpreadsheetApp) at$0.003(3 credits) per profile call. - Keys kept out of cells: Reads
SOCIALSCRAPER_API_KEYandINSTAGRAM_HANDLEfromPropertiesService.getScriptProperties(). - Formula-safe Sheet cells: Prefixes
@handleand=,+,-strings with'to prevent Sheets formula parsing; leaves missing counts blank. - Fail-closed error handling: Uses
muteHttpExceptions: trueand throws cleanly on HTTP401before appending any row.

instagram.profilePaid connectors like Supermetrics focus on private Meta Insights (reach, impressions, ad spend) for Business accounts you own. When you need public metrics for creators, partners, or competitors you do not own—and cannot authorize via Facebook OAuth—a 15-line Google Apps Script calling GET /v1/instagram/profile replaces recurring connector subscriptions with $0.003 per lookup.
Apps Script REST Calls vs Paid Sheets Add-Ons
Choose your integration based on whether you need private Meta Insights for your own Business account or public profile metrics across third-party handles:
| Option | Monthly connector fee | Third-party public accounts | Auth & ownership |
|---|---|---|---|
Native Apps Script + Social Media Scraper (instagram-google-sheets.js) | $0 add-on fee; $0.003 (3 credits) per profile request | Yes — any public Instagram handle | API key in Script Properties; zero Marketplace add-on scopes |
| Supermetrics / enterprise connectors | $30–$99+/mo recurring plans | Built primarily for owned Business accounts via Meta OAuth | Requires Facebook Business OAuth + vendor Workspace add-on |
| Marketplace add-ons (API Connector, instagReader) | Freemium caps; paid tiers for scheduled triggers | Depends on connected endpoint | Third-party add-on holds OAuth scopes on your Sheets |
| Manual copy-paste | $0 software cost, high manual effort | Yes, manually | No scheduled snapshots or automated history |
Use official Meta Insights connectors for private reach or impressions on owned brand profiles. For public creator shortlists and weekly competitor follower logs inside Google Sheets, native Apps Script keeps both costs and code under your own Google Drive.
Fields Imported and Credential Hygiene in Google Sheets
importInstagramProfile() calls Instagram Profile API (GET https://socialmediascraper.org/v1/instagram/profile?handle=...). The starter writes fetched_at, handle, profile_url, and followers, and you can include any additional normalized fields below:
| JSON path | Type | Spreadsheet handling |
|---|---|---|
data.handle | String | Wrap in safe() so leading @ never triggers Sheets formula parsing |
data.display_name & data.bio | String | Wrap in safe() in case text starts with =, +, -, or @ |
data.profile_url | String | Canonical public link for direct audit click-through |
data.verified & data.private | Boolean | Verification badge and public/private account status |
data.metrics.{followers,following,posts} | Number or null | Write ?? '' for null—never substitute 0 |
- Never put keys in sheet cells: Storing
SOCIALSCRAPER_API_KEYin cellB1exposes it to viewers, version history, and CSV exports. Always store secrets in Project Settings > Script Properties. - Built-in idempotency header:
Utilities.getUuid()supplies a uniqueIdempotency-Keyon every request without external packages. - Fail before appending:
muteHttpExceptions: truelets the script throwHTTP 401(or402/429) beforeappendRowwrites corrupt rows.
Step-by-Step Setup to Import Instagram Data into Google Sheets
Follow these four steps to run instagram-google-sheets.js (shown right below) inside any Google Sheet—no Marketplace installs or Node.js required.
Open Apps Script and paste instagram-google-sheets.js
In Google Sheets, open Extensions > Apps Script, replace
Code.gswith the completeimportInstagramProfile()script below, and save.Save SOCIALSCRAPER_API_KEY and INSTAGRAM_HANDLE in Script Properties
Click Project Settings (gear icon), scroll to Script Properties, and add
SOCIALSCRAPER_API_KEY(your customer API key) andINSTAGRAM_HANDLE(a public username such asinstagramor@creatorhandle). Never store your key in spreadsheet cells.Run importInstagramProfile and authorize scopes
Select
importInstagramProfilein the editor toolbar and click Run. Approve Google's one-time prompt granting your own scriptUrlFetchAppandSpreadsheetApppermissions.Verify the Instagram tab headers and escaped handle
Back in your spreadsheet, confirm the
Instagramtab created headersfetched_at | handle | profile_url | followers, escaped@handlesafely with', and appended the numeric follower count.
function importInstagramProfile() {
const key = PropertiesService.getScriptProperties().getProperty('SOCIALSCRAPER_API_KEY');
const handle = PropertiesService.getScriptProperties().getProperty('INSTAGRAM_HANDLE');
if (!key || !handle) throw new Error('Set SOCIALSCRAPER_API_KEY and INSTAGRAM_HANDLE in Script Properties');
const response = UrlFetchApp.fetch('https://socialmediascraper.org/v1/instagram/profile?handle=' + encodeURIComponent(handle), {
headers: {'x-api-key': key, 'Idempotency-Key': Utilities.getUuid()}, muteHttpExceptions: true
});
if (response.getResponseCode() !== 200) throw new Error('HTTP ' + response.getResponseCode());
const data = JSON.parse(response.getContentText()).data;
if (!data) throw new Error('Response has no data');
const book = SpreadsheetApp.getActiveSpreadsheet();
const sheet = book.getSheetByName('Instagram') || book.insertSheet('Instagram');
if (sheet.getLastRow() === 0) sheet.appendRow(['fetched_at', 'handle', 'profile_url', 'followers']);
const safe = value => /^[\s]*[=+\-@]/.test(String(value ?? '')) ? "'" + String(value) : String(value ?? '');
sheet.appendRow([new Date().toISOString(), safe(data.handle), safe(data.profile_url), data.metrics?.followers ?? '']);
}
Tracking Multiple Handles and Scheduling Automatic Refreshes
To refresh 20–100 accounts on a schedule, list one public handle per row in column A (A2:A) of a Handles tab and add this batch function to Code.gs:
function refreshInstagramShortlist() {
const key = PropertiesService.getScriptProperties().getProperty('SOCIALSCRAPER_API_KEY');
if (!key) throw new Error('Set SOCIALSCRAPER_API_KEY in Script Properties');
const book = SpreadsheetApp.getActiveSpreadsheet();
const inputSheet = book.getSheetByName('Handles');
if (!inputSheet) throw new Error('Create a tab named Handles with usernames in A2:A');
const outSheet = book.getSheetByName('Instagram') || book.insertSheet('Instagram');
if (outSheet.getLastRow() === 0) {
outSheet.appendRow(['fetched_at', 'handle', 'display_name', 'followers', 'following', 'posts', 'verified', 'profile_url']);
}
const safe = v => /^[\s]*[=+\-@]/.test(String(v ?? '')) ? "'" + String(v) : String(v ?? '');
const handles = inputSheet.getRange('A2:A' + inputSheet.getLastRow()).getValues()
.map(r => String(r[0] || '').trim()).filter(Boolean);
const rows = [];
const now = new Date().toISOString();
for (let i = 0; i < handles.length; i++) {
const url = 'https://socialmediascraper.org/v1/instagram/profile?handle=' + encodeURIComponent(handles[i]);
const res = UrlFetchApp.fetch(url, {
headers: {'x-api-key': key, 'Idempotency-Key': Utilities.getUuid()},
muteHttpExceptions: true
});
if (res.getResponseCode() !== 200) throw new Error('Stopped at ' + handles[i] + ': HTTP ' + res.getResponseCode());
const d = JSON.parse(res.getContentText()).data;
if (d) {
rows.push([now, safe(d.handle), safe(d.display_name), d.metrics?.followers ?? '', d.metrics?.following ?? '', d.metrics?.posts ?? '', d.verified ?? '', safe(d.profile_url)]);
}
if (i < handles.length - 1) Utilities.sleep(1100); // stay under 60 req/min
}
if (rows.length) outSheet.getRange(outSheet.getLastRow() + 1, 1, rows.length, rows[0].length).setValues(rows);
}
Schedule hands-off updates under Triggers > Add Trigger, selecting refreshInstagramShortlist with a Time-driven weekly or daily timer. Expand your workbook with companion endpoints at the same $0.003 (3 credits) rate:
- Instagram Profile Posts (
GET /v1/instagram/posts): recent posts byhandle(paginate withnext_max_id). - Instagram Profile Reels (
GET /v1/instagram/reels): recent Reels byhandleoruser_id(paginate withmax_id). - Instagram Profile Post Count (
GET /v1/instagram/profile_post_count): quick post-count check byhandle.
Troubleshooting Apps Script Errors and Google Quotas
HTTP 401, 402, or 429 in execution logs
Check Executions in Apps Script. HTTP 401 points to a missing or wrong SOCIALSCRAPER_API_KEY in Script Properties; HTTP 402 means prepaid balance is depleted; HTTP 429 means your loop exceeded 60 req/min (GET /v1/limits). Because status is checked before appendRow, failures never corrupt your tab.
Leading apostrophe on handles and blank metrics
Sheets displays '@creator cleanly as @creator while storing a leading apostrophe in the formula bar to prevent #NAME? errors and formula injection. Keeping missing counts as '' instead of 0 protects AVERAGE() and growth charts.
Apps Script 6-minute timeout and UrlFetch quotas
Google Apps Script enforces a 6-minute execution limit and daily UrlFetchApp quotas. At 1.1 seconds per handle, one trigger processes ~100–200 profiles comfortably; for 300+ accounts or multi-app routing, move to n8n Instagram workflows.
Monthly Reporting Cost Math vs SaaS Connectors
Under price book 2026-12-02.credits-3 (1,000 credits = $1), GET /v1/instagram/profile costs $0.003 (3 credits) per lookup ($3.00 per 1,000 requests). Compare typical monthly cadences against $30–$99/month connector seats:
| Reporting cadence | Monthly requests | Monthly USD cost |
|---|---|---|
| 50 accounts refreshed weekly (4×/mo) | 200 × instagram.profile | $0.60 / month |
| 250 competitor profiles refreshed monthly | 250 × instagram.profile | $0.75 / month |
| 100 accounts weekly (profile + 1 posts page) | 800 standard requests | $2.40 / month |
| 50 priority accounts refreshed daily (30×/mo) | 1,500 × instagram.profile | $4.50 / month |
New accounts start with 100 starter credits ($0.10, ~33 lookups), and one-time prepaid USD packs fund ongoing schedules—$5 (5,000 credits, ~1,666 lookups—over 8 months of weekly 50-account tracking), $20 (20,000 credits, ~6,666), or $50 (50,000 credits, ~16,666)—with no subscription or auto-renewal. Check pricing or pricing-data.json.
What Teams Track in Instagram Google Sheets
Influencer shortlists and vetting logs
List candidate handles in Handles to pull bio text, verified status, post volume, and follower tiers—supporting broader influencer marketing workflows.
Weekly competitor follower snapshots
Run a Monday trigger appending fetched_at beside follower totals so teams chart week-over-week growth directly in Sheets or Looker Studio. See competitor intelligence.
Recent post and Reel cadence tables
Pair profile pulls with /v1/instagram/posts and /v1/instagram/reels on secondary tabs to audit posting cadence and public engagement counts.
Pick the Right Instagram Tracking Workflow
Marketing ops and agency analysts
Use this Apps Script guide when Google Sheets is your reporting surface and you want sub-dollar weekly tracking without Marketplace add-ons.
Automation builders routing to CRMs or Slack
Need webhook alerts, Airtable syncing, or Postgres upserts beyond Sheets quotas? Switch to n8n Instagram integration or social media analytics.
Single-account browser lookups
Inspect one public account right away without Apps Script or an API key using the free Instagram Profile Viewer.
Scope Limits, Google Quotas, and Data Usage
GET /v1/instagram/profile returns read-only public profile data. It does not access private profiles, DMs, Story viewers, or private Meta Business Insights (reach, impressions, profile visits, demographics).
- Time-driven triggers run inside your Google account subject to Google Apps Script runtime and
UrlFetchAppquotas. - Keep
SOCIALSCRAPER_API_KEYin Script Properties and grant clients Viewer access (not Editor access) on sheets bound to live keys. - Review service status and API docs before deploying daily triggers, and respect Instagram terms, copyright, and privacy laws.
Instagram to Google Sheets Apps Script Questions
How do I connect Instagram data to Google Sheets without paying for Supermetrics?
Open Extensions > Apps Script, paste instagram-google-sheets.js, save SOCIALSCRAPER_API_KEY and INSTAGRAM_HANDLE in Project Settings > Script Properties, and run importInstagramProfile(). You pay $0 for add-ons and $0.003 (3 credits) per lookup.
Is my API key safe if I share the Google Sheet with clients?
Never store keys in spreadsheet cells. Using PropertiesService.getScriptProperties() hides keys from cells and CSV exports; grant clients Viewer access (since Editors can open the bound Apps Script project).
Can I schedule automatic daily or weekly refreshes in Google Sheets?
Yes. Open Triggers > Add Trigger in Apps Script, pick importInstagramProfile or refreshInstagramShortlist, choose Time-driven, and set a daily or weekly timer.
What Instagram metrics can I pull into Google Sheets?
GET /v1/instagram/profile returns handle, display_name, bio, profile_url, avatar_url, verified, private, and metrics.{followers,following,posts}. Add recent posts via Instagram Profile Posts or Reels via Instagram Profile Reels at $0.003/request.
Can this script pull Instagram Insights like impressions or reach?
No. Impressions, reach, and demographic splits are private Meta Business Insights requiring official Meta OAuth for accounts you administer. This API retrieves read-only public profile metrics.
Why does the script prepend a single quote to @handle?
Google Sheets parses cells starting with =, +, -, or @ as formulas. The safe() helper prefixes them with ' so Sheets displays @handle cleanly as literal text without #NAME? errors.
What happens if my API key fails during a scheduled trigger?
instagram-google-sheets.js sets muteHttpExceptions: true and checks response.getResponseCode() !== 200 before writing. On HTTP 401 or 402, it throws cleanly in Executions without appending broken rows.
How much does refreshing 50 Instagram accounts weekly cost?
50 profiles × 4 weekly runs = 200 requests/month = $0.60/month at $0.003 (3 credits)/request. One $5 prepaid pack (5,000 credits) covers over 8 months with no subscription.
Can I also import public Instagram Reels or posts into another tab?
Yes. Call GET /v1/instagram/posts?handle=... or GET /v1/instagram/reels?handle=... ($0.003/page) and write data.items[] into a second tab with setValues(). See Instagram Profile Reels API.
Can I import data from a private Instagram account?
No. Only publicly accessible Instagram profile fields are supported.
How many handles can one Apps Script trigger refresh at once?
With Utilities.sleep(1100) staying under 60 req/min, one trigger refreshes ~100–200 handles inside Google's 6-minute execution limit. For larger rosters, split batches or move to n8n.
Can I track TikTok or YouTube accounts in the same Google Sheet?
Yes. Reuse the same x-api-key and Idempotency-Key pattern with /v1/tiktok/profile or /v1/youtube/profile inside Apps Script. Explore the profiles capability page.