Motivation

Whenever you let people sign up with a social handle, you need to check that handle. Creator programs, reward campaigns and affiliate signups all have the same problem: people mistype their handle, enter someone else's, or make a new account just to join.

In this post we will verify TikTok and Instagram accounts in Node JS, with rules for whether the account exists, whether it is public, how many followers it has and how old it is.

Introduction

Each account gets one of three results:

  • approve: it passed every rule.
  • reject: it clearly failed a rule.
  • review: the platform didn't give us enough to decide, so a person should check.

The review result matters more than it looks. The Instagram profile data has no account creation date, so a minimum age rule can't be checked there. If we treated that missing date as a failure, we would reject every Instagram account.

I am reading the profiles with TrueScrape, which I built. It only reads public data with no login.

Installation

Nothing to install, just Node 18 or above. Set your API key in the terminal:

export TRUESCRAPE_API_KEY=your_key 

Step 1: Create the API Helper

Create a file called accounts.mjs and paste this:

async function api(path, params) { const url = new URL(`https://api.truescrape.com/v1${path}`); url.search = new URLSearchParams(params); const res = await fetch(url, { headers: { 'x-api-key': process.env.TRUESCRAPE_API_KEY }, }); const json = await res.json(); if (!json.success) { const error = new Error(json.error.message); error.code = json.error.code; throw error; } return json; } 

Step 2: Check the Account

const DAY = 24 * 60 * 60 * 1000; async function checkAccount(platform, handle, rules) { let account; try { ({ data: account } = await api(`/${platform}/profile`, { handle })); } catch (error) { if (error.code === 'upstream_not_found') { return { status: 'reject', reasons: ['account is missing, private or removed'] }; } return { status: 'review', reasons: [`could not check: ${error.code}`] }; } const failed = []; const unsure = []; if (account.isPrivate === true) failed.push('account is private'); if (account.followerCount === null) { unsure.push('follower count not available'); } else if (account.followerCount < rules.minFollowers) { failed.push(`only ${account.followerCount} followers`); } if (account.createdAt === null) { unsure.push('account age not available'); } else { const ageInDays = (Date.now() - new Date(account.createdAt)) / DAY; if (ageInDays < rules.minAgeDays) failed.push(`account is ${Math.floor(ageInDays)} days old`); } if (failed.length > 0) return { status: 'reject', reasons: failed }; if (unsure.length > 0) return { status: 'review', reasons: unsure }; return { status: 'approve', reasons: [] }; } 

Usage

const rules = { minFollowers: 500, minAgeDays: 30 }; console.log(await checkAccount('tiktok', 'nike', rules)); console.log(await checkAccount('instagram', 'natgeo', rules)); console.log(await checkAccount('tiktok', 'zzz_no_such_account_8841', rules)); 

Run it with node accounts.mjs and you will get this output:

{ status: 'approve', reasons: [] } { status: 'review', reasons: [ 'account age not available' ] } { status: 'reject', reasons: [ 'account is missing, private or removed' ] } 

The Instagram account goes to review because of the missing date. If you run Instagram campaigns, remove the age rule for that platform so you don't have to review every account.

Things to Know

  • A real account is not the same as the right person. This shows the account exists, not that the person filling your form owns it. To prove ownership, ask them to put a short code from your site in their bio, then read bio from the same response.
  • Followers can be bought. A follower minimum filters out throwaway accounts, but it doesn't detect fake followers.
  • Private and missing look the same. For a private account the platform may show nothing at all, so the reason says "missing, private or removed".
  • Cost. Each check is 1 credit, and a failed check is free.

Frequently Asked Questions

Can I check other platforms?
Yes, checkAccount takes the platform name, and threads and snapchat work the same way. They don't all return the same fields, which is why each missing value goes to review.

How do I check a whole list?
Loop through it a few at a time. Sending thousands of requests at once won't make the result any better.

Thanks for reading, Cheers.