instagram-scraper

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Instagram Scraper

Instagram Scraper

Public Instagram data via Apify's Instagram Scraper. No Instagram login, no cookies, no Meta app review.
Actor
apify/instagram-scraper
Auth
Authorization: Bearer $APIFY_TOKEN
, or a logged-in Apify CLI — see Setup
Pricefrom $2.30 per 1,000 results, billed by Apify
Free tier$5/month credits ≈ 2,000+ results, no credit card

通过Apify的Instagram Scraper获取公开的Instagram数据。无需登录Instagram,无需Cookie,无需Meta应用审核。
Actor
apify/instagram-scraper
认证方式
Authorization: Bearer $APIFY_TOKEN
,或已登录的Apify CLI — 详见设置部分
价格每1000条结果起价2.30美元,由Apify计费
免费额度每月5美元信用额度 ≈ 2000+条结果,无需信用卡

Setup — do this before any data call

设置——在任何数据调用前完成此步骤

Always run this preflight first. Do not attempt a data call until it passes.
bash
if [ -n "$APIFY_TOKEN" ]; then
  echo "AUTH_OK curl"
elif command -v apify >/dev/null 2>&1 && apify info >/dev/null 2>&1; then
  echo "AUTH_OK cli: apify"
elif { [ -f "$HOME/.apify/auth.json" ] || [ -f "$USERPROFILE/.apify/auth.json" ]; } \
     && npx --yes apify-cli@latest info >/dev/null 2>&1; then
  echo "AUTH_OK cli: npx --yes apify-cli@latest"
else
  echo "AUTH_MISSING"
fi
The checks are ordered cheapest-first. The
npx
fallback costs about four seconds, so it only runs when an Apify config directory shows a previous login — a first-time user reaches
AUTH_MISSING
instantly rather than waiting for a package download that was never going to find a session.
$HOME
and
$USERPROFILE
are both checked on purpose.
On Windows they can point to different places — sandboxes and some CI images remap
$HOME
while the Apify CLI keeps writing to
$USERPROFILE\.apify
. Testing only
$HOME
there reports
AUTH_MISSING
for a user who is perfectly well logged in, and the skill would then send them to sign up for an account they already have. If you see
AUTH_MISSING
on a machine you believe is authenticated, check both paths before trusting it.
The two
AUTH_OK
modes are not interchangeable — the preflight tells you which call form to use.
  • AUTH_OK curl
    — a token is in the environment. The HTTP calls in this skill work as written.
  • AUTH_OK cli: <prefix>
    — the Apify CLI holds the session and the token is not readable from disk.
    ~/.apify/auth.json
    carries account metadata only (username, plan, proxy groups — no
    token
    field); current CLI versions keep the token in the OS secrets backend. Do not try to extract one from that file: a bogus
    Authorization: Bearer
    header returns
    401
    and looks exactly like a revoked token. Use
    apify call
    instead, prefixed with whatever the preflight printed after
    cli:
    (
    apify
    , or
    npx --yes apify-cli@latest
    when the CLI is not on
    PATH
    ).
请务必先运行此预检步骤。 在预检通过前,请勿尝试进行数据调用。
bash
if [ -n "$APIFY_TOKEN" ]; then
  echo "AUTH_OK curl"
elif command -v apify >/dev/null 2>&1 && apify info >/dev/null 2>&1; then
  echo "AUTH_OK cli: apify"
elif { [ -f "$HOME/.apify/auth.json" ] || [ -f "$USERPROFILE/.apify/auth.json" ]; } \
     && npx --yes apify-cli@latest info >/dev/null 2>&1; then
  echo "AUTH_OK cli: npx --yes apify-cli@latest"
else
  echo "AUTH_MISSING"
fi
检查顺序按照成本从低到高排列。
npx
回退方案大约耗时4秒,因此仅在Apify配置目录显示之前有登录记录时才会运行——首次使用的用户会立即得到
AUTH_MISSING
结果,无需等待永远找不到会话的包下载。
特意同时检查
$HOME
$USERPROFILE
在Windows系统中,它们可能指向不同的位置——沙箱和部分CI镜像会重新映射
$HOME
,而Apify CLI始终将内容写入
$USERPROFILE\.apify
。如果仅测试
$HOME
,可能会导致已正常登录的用户得到
AUTH_MISSING
结果,进而引导他们注册已有的账户。如果您认为已认证的机器显示
AUTH_MISSING
,请先检查这两个路径再下结论。
两种
AUTH_OK
模式不可互换——预检会告知您应使用哪种调用形式。
  • AUTH_OK curl
    — 环境中存在令牌。本技能中的HTTP调用可直接使用。
  • AUTH_OK cli: <prefix>
    — Apify CLI保存会话,且令牌无法从磁盘读取
    ~/.apify/auth.json
    仅包含账户元数据(用户名、套餐、代理组——无
    token
    字段);当前CLI版本将令牌存储在操作系统的密钥管理后端。请勿尝试从该文件提取令牌:伪造的
    Authorization: Bearer
    标头会返回
    401
    ,与令牌失效的表现完全一致。请改用
    apify call
    ,前缀使用预检结果中
    cli:
    后的内容(
    apify
    ,或当CLI不在
    PATH
    中时使用
    npx --yes apify-cli@latest
    )。

If the preflight prints
AUTH_OK cli

如果预检结果为
AUTH_OK cli

Every payload in this skill still applies — write it to a file and hand it to
apify call
instead of
curl
:
bash
cat > /tmp/ig-input.json <<'EOF'
{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"details","resultsLimit":1}
EOF

apify call apify/instagram-scraper --input-file /tmp/ig-input.json --output-dataset --silent
  • Always pass the Actor id explicitly. With no id,
    apify call
    runs the Actor defined by a local
    .actor/actor.json
    — inside an Actor repo that silently runs the wrong thing.
  • Prefer
    --input-file
    over inline
    -i '{...}'
    .
    Inline JSON has to survive the shell, and PowerShell and
    cmd.exe
    mangle the quoting. A file never does.
    --input-file -
    reads stdin.
  • --output-dataset
    prints the dataset to stdout
    — the same array
    run-sync-get-dataset-items
    returns, so every field in the Output section below is identical.
    --silent
    keeps run logs off stdout so the output parses as JSON.
  • apify call
    waits for the run to finish, so the async polling pattern below is only needed on the
    curl
    path. Add
    --timeout <seconds>
    to bound a long job.
  • The run is billed to whichever account the CLI is logged in as.
    apify info
    prints it — worth showing the user if they may have more than one.
本技能中的所有请求参数仍然适用——将其写入文件,然后通过
apify call
而非
curl
执行:
bash
cat > /tmp/ig-input.json <<'EOF'
{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"details","resultsLimit":1}
EOF

apify call apify/instagram-scraper --input-file /tmp/ig-input.json --output-dataset --silent
  • 请始终显式传递Actor ID。 如果不指定ID,
    apify call
    会运行本地
    .actor/actor.json
    中定义的Actor——在Actor仓库中可能会静默执行错误的任务。
  • 优先使用
    --input-file
    而非内联
    -i '{...}'
    内联JSON需要在shell中正确解析,而PowerShell和
    cmd.exe
    会破坏引号格式。使用文件则不会出现此问题。
    --input-file -
    表示从标准输入读取。
  • --output-dataset
    会将数据集打印到标准输出
    ——与
    run-sync-get-dataset-items
    返回的数组相同,因此下方输出部分的所有字段完全一致。
    --silent
    会阻止运行日志输出到标准输出,确保输出可解析为JSON。
  • apify call
    会等待运行完成,因此下方的异步轮询模式仅适用于
    curl
    路径。可添加
    --timeout <seconds>
    来限制长任务的运行时间。
  • 运行费用将计入CLI登录的账户。
    apify info
    会显示该账户——如果用户可能拥有多个账户,建议告知用户。

If the preflight prints
AUTH_MISSING

如果预检结果为
AUTH_MISSING

Open the Apify sign-up page in the user's browser, then ask for the token. Run this exactly as-is — it picks the right command per platform and degrades to printing the URL when there is no browser (CI, SSH, containers):
bash
URL="https://console.apify.com/sign-up?fpr=z8j1nz"
在用户浏览器中打开Apify注册页面,然后请求令牌。请严格按以下命令执行——它会根据平台选择正确的命令,在无法打开浏览器的环境(CI、SSH、容器)中会降级为打印URL:
bash
URL="https://console.apify.com/sign-up?fpr=z8j1nz"

xdg-open is checked before open: on some Linux distros
open
is openvt, not a browser.

优先检查xdg-open:在部分Linux发行版中,
open
是openvt而非浏览器。

if command -v xdg-open >/dev/null 2>&1; then xdg-open "$URL" elif command -v open >/dev/null 2>&1; then open "$URL" elif command -v powershell.exe >/dev/null 2>&1; then powershell.exe -NoProfile -Command "Start-Process '$URL'" elif command -v cmd.exe >/dev/null 2>&1; then cmd.exe /c start "" "$URL" else echo "Open this URL in a browser: $URL" fi

Then tell the user what is happening — but **do not wait for a reply**:

> I've opened Apify's sign-up page in your browser. Instagram data comes through
> Apify, which is free to start — $5 of credits every month, no credit card, enough
> for around 2,000 results.
>
> Sign up there (or log in, if you already have an account). I'm opening the
> authorisation step now too — approve it and this machine stays connected, so you
> won't have to do any of this again.
>
> _The sign-up link is a referral link._

Immediately run the login. **Do not ask the user to confirm they've signed up first** —
this command opens Apify's authorisation page, which offers sign-up itself, and then
blocks until the user finishes. The command *is* the wait, so there is nothing to
detect and no round trip to burn:

```bash
timeout 300 npx --yes apify-cli@latest login -m console
  • -m console
    is required.
    Bare
    apify login
    first prompts for a login method and will hang forever on stdin the agent cannot answer.
    -m console
    goes straight to the browser flow.
  • timeout 300
    bounds it, so an abandoned sign-up doesn't hang the session. Exit code
    124
    means it timed out — the user walked away, so ask whether they still want to continue rather than silently retrying.
  • On success it prints "Success: You are logged in to Apify as
    <username>
    . Your token is stored in your OS keyring."
    From then on the preflight resolves to
    AUTH_OK cli
    in every future session — no token to paste, store, or leak into a transcript.
Then re-run the preflight. That is how you know whether it worked — not the message, and not an assumption that the browser step went fine:
Preflight now saysMeaningDo
AUTH_OK cli: <prefix>
Logged in and persistedContinue with the request
AUTH_MISSING
Login did not completeSay so plainly and ask whether to retry — do not loop
The preflight's CLI branch is just
apify info
, which exits
0
when a session exists and non-zero when it doesn't. It is the same check that produced
AUTH_MISSING
a moment earlier, so re-running it is a genuine confirmation rather than a restatement of what you already believed.
Two failure modes worth naming, because both look like success from the outside: the user closes the authorisation tab without approving (exit
124
at the timeout), and the user signs up but never reaches the approval step. In both the sign-up may well have succeeded while this machine is still not connected — which is exactly why the preflight, not the sign-up, is the thing to trust.
Keep the sign-up tab and the login in that order. The sign-up page is where the referral is recorded; the authorisation step afterwards is just this machine connecting to whichever account now exists. Opening them the other way round loses the attribution.
if command -v xdg-open >/dev/null 2>&1; then xdg-open "$URL" elif command -v open >/dev/null 2>&1; then open "$URL" elif command -v powershell.exe >/dev/null 2>&1; then powershell.exe -NoProfile -Command "Start-Process '$URL'" elif command -v cmd.exe >/dev/null 2>&1; then cmd.exe /c start "" "$URL" else echo "请在浏览器中打开此URL:$URL" fi

然后告知用户当前操作——但**请勿等待回复**:

> 我已在您的浏览器中打开Apify的注册页面。Instagram数据通过Apify获取,Apify免费入门——每月提供5美元信用额度,无需信用卡,可获取约2000条结果。
>
> 请在该页面注册(或登录已有账户)。我现在将打开授权步骤页面——完成授权后,此机器将保持连接,您无需再重复此操作。
>
> _该注册链接为推荐链接。_

立即运行登录命令。**请勿先询问用户是否已完成注册**——此命令会打开Apify的授权页面,该页面本身也提供注册选项,然后会阻塞直到用户完成操作。该命令本身就是等待过程,因此无需检测或往返通信:

```bash
timeout 300 npx --yes apify-cli@latest login -m console
  • 必须添加
    -m console
    不带参数的
    apify login
    会先提示选择登录方式,若代理无法回答则会在标准输入处永久挂起。
    -m console
    会直接进入浏览器流程。
  • **
    timeout 300
    **用于限制超时时间,避免未完成的注册导致会话挂起。退出码
    124
    表示超时——用户已离开,应询问用户是否继续,而非静默重试。
  • 成功时会打印*"Success: You are logged in to Apify as
    <username>
    . Your token is stored in your OS keyring."* 此后,在所有未来会话中预检结果都会是
    AUTH_OK cli
    ——无需粘贴、存储令牌,也不会在会话记录中泄露令牌。
然后重新运行预检步骤。这是验证是否成功的唯一方式——不要依赖提示信息,也不要假设浏览器步骤已成功完成:
当前预检结果含义操作
AUTH_OK cli: <prefix>
已登录且会话已持久化继续处理用户请求
AUTH_MISSING
登录未完成明确告知用户,并询问是否重试——请勿循环执行
预检的CLI分支仅执行
apify info
,当会话存在时返回退出码
0
,不存在时返回非零值。这与之前产生
AUTH_MISSING
的检查逻辑相同,因此重新运行预检是真实的确认,而非重复您已有的假设。
有两种值得注意的失败模式,从外部看都像是成功:用户未批准就关闭授权标签页(超时后退出码
124
),以及用户完成注册但未进入授权步骤。这两种情况下,注册可能已成功,但此机器仍未连接——这正是为什么要信任预检结果而非注册流程的原因。
请保持先打开注册标签页再执行登录的顺序。 注册页面会记录推荐信息;后续的授权步骤只是让此机器连接到已创建的账户。如果顺序颠倒,将无法记录推荐归属。

Never ask the user for their token

切勿向用户索要令牌

Do not request, accept, or handle an Apify API token in the conversation. The browser login above exists precisely so the secret never reaches the agent: the CLI receives it directly from Apify and writes it to the OS keyring, and this skill only ever reads the result of that (
apify info
's exit code), never the value.
If the user offers a token unprompted, decline it and point them at one of the two safe routes below. Anything pasted into a session is a live credential sitting in a transcript, in scrollback, and in any log that captures the conversation.
Headless environments — CI, SSH, containers, anywhere the OAuth round trip cannot open a browser. The user sets the credential themselves, out of band, before starting the agent:
bash
undefined
请勿在对话中请求、接受或处理Apify API令牌。 上述浏览器登录流程的存在正是为了避免密钥传递到代理:CLI直接从Apify接收令牌并写入操作系统密钥管理,本技能仅读取该操作的结果
apify info
的退出码),绝不会读取令牌值。
如果用户主动提供令牌,请拒绝并引导他们使用以下两种安全方式之一。 粘贴到会话中的任何内容都是有效的凭证,会保存在会话记录、回滚缓冲区和所有捕获对话的日志中。
无头环境——CI、SSH、容器等无法完成OAuth往返流程打开浏览器的环境。用户需在启动代理之前,自行在外部设置凭证:
bash
undefined

the user runs this in their own shell / CI secret store — not via the agent

用户需在自己的shell/CI密钥存储中执行此命令——不要通过代理执行

export APIFY_TOKEN="…"

The preflight then reports `AUTH_OK curl` and everything works, with the value never
passing through the conversation.

**Or the CLI's own prompt**, which reads the token from stdin rather than the
conversation:

```bash
npx --yes apify-cli@latest login -m manual
Avoid
login -t <token>
. Passing a secret as a command-line argument exposes it in the process list to every other process on the machine, and in shell history. It also clears the stored session before validating, so a typo or a stale value logs the user out of a session that was working.
When a token does legitimately exist in the environment, always reference it as
$APIFY_TOKEN
and let the shell expand it — as every example in this skill does. Never substitute the literal value into a command, a log line, or a message.

export APIFY_TOKEN="…"

此后预检结果会显示`AUTH_OK curl`,所有操作均可正常进行,且令牌值不会通过对话传递。

**或使用CLI自身的提示**,它会从标准输入读取令牌而非对话:

```bash
npx --yes apify-cli@latest login -m manual
避免使用
login -t <token>
。将密钥作为命令行参数传递会暴露给机器上的所有其他进程,也会保存在shell历史记录中。此外,它还会在验证前清除已存储的会话,因此输入错误或过期的令牌会导致用户退出原本正常的会话。
当环境中确实存在令牌时,请始终以
$APIFY_TOKEN
引用它,让shell自动展开——如本技能中的所有示例所示。切勿将字面值替换到命令、日志行或消息中。

Fetching data

获取数据

One call, synchronous, returns the items directly. Good for anything that finishes inside ~60 s. This is the
AUTH_OK curl
form
— under
AUTH_OK cli
, put the same
-d
payload in a file and run it through
apify call
as shown above.
bash
curl -s -X POST \
  "https://api.apify.com/v2/acts/apify~instagram-scraper/run-sync-get-dataset-items?timeout=120" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -H "User-Agent: instagram-scraper-skill" \
  -d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"details","resultsLimit":1}'
The
User-Agent
header is only so runs originating from this skill can be told apart in logs. It carries no personal data and can be removed.
单次同步调用,直接返回结果项。适用于约60秒内可完成的任务。以下是
AUTH_OK curl
模式的调用方式
——在
AUTH_OK cli
模式下,将相同的
-d
参数写入文件,然后按上述方式通过
apify call
执行。
bash
curl -s -X POST \
  "https://api.apify.com/v2/acts/apify~instagram-scraper/run-sync-get-dataset-items?timeout=120" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -H "User-Agent: instagram-scraper-skill" \
  -d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"details","resultsLimit":1}'
User-Agent
标头仅用于在日志中区分来自本技能的运行请求。它不包含个人数据,可移除。

Choosing
resultsType

选择
resultsType

ValueReturns
details
Profile metadata: followers, following, bio, post count, profile picture. Cheapest — 1 result per profile.
posts
A feed of posts
reels
Reels only
stories
Currently-live stories
comments
Comments on a post URL
mentions
Posts mentioning an account
Pick
details
whenever the user only needs profile numbers. Using
posts
for that question costs up to 100× more for no benefit.
返回内容
details
个人资料元数据:粉丝数、关注数、简介、帖子数量、头像。成本最低——每个个人资料返回1条结果。
posts
帖子动态
reels
仅Reels内容
stories
当前在线的快拍
comments
帖子URL对应的评论
mentions
提及该账户的帖子
当用户仅需要个人资料数据时,选择
details
。使用
posts
来获取此类信息会多花费高达100倍的成本,且无任何额外收益。

Input reference

参数参考

FieldTypeDefaultNotes
directUrls
arrayProfile, post, reel, hashtag, location or audio URLs — see URL handling below
resultsType
string
posts
See table above
resultsLimit
integer
100
Per URL. Drives cost — always set it.
onlyPostsNewerThan
string
YYYY-MM-DD
, ISO, or
1 day
/
2 months
. UTC
search
stringKeyword, instead of
directUrls
searchType
string
hashtag
hashtag
,
profile
,
place
,
user
searchLimit
integer
10
Max items discovered per search
addParentData
boolean
false
Stamps each item with the query that produced it
Four more fields work but are not in the published input schema. They are documented in the Actor's README and verified working — use them freely:
FieldTypeApplies toNotes
addProfileStatistics
boolean
details
Adds a
statistics
object (~60 fields) —
account_type
(1 Personal, 2 Business, 3 Creator),
media_count
,
total_clips_count
,
category
,
city_name
, contact fields. Works on private profiles too
skipPinnedPosts
boolean
posts
Exclude pinned posts
isNewestComments
boolean
comments
Newest-first ordering. Paid plans only — free plans get default order
includeNestedComments
boolean
comments
Include replies. Paid plans only. Each reply is a separate result, so totals exceed
resultsLimit
字段类型默认值说明
directUrls
数组个人资料、帖子、Reels、话题标签、地点或音频URL——详见下方URL处理部分
resultsType
字符串
posts
见上方表格
resultsLimit
整数
100
每个URL对应的结果数。决定成本——请始终设置此参数。
onlyPostsNewerThan
字符串
YYYY-MM-DD
格式、ISO格式,或
1 day
/
2 months
。使用UTC时间
search
字符串关键词,替代
directUrls
searchType
字符串
hashtag
hashtag
profile
place
user
searchLimit
整数
10
每次搜索最多发现的结果项数
addParentData
布尔值
false
为每个结果项添加生成它的查询信息
还有四个字段可用,但未在公开的参数 schema 中列出。 它们已在Actor的README中记录并验证可用——可自由使用:
字段类型适用场景说明
addProfileStatistics
布尔值
details
添加
statistics
对象(约60个字段)——
account_type
(1=个人,2=企业,3=创作者)、
media_count
total_clips_count
category
city_name
、联系字段。对私密个人资料也有效
skipPinnedPosts
布尔值
posts
排除置顶帖子
isNewestComments
布尔值
comments
按最新顺序排序。仅付费套餐可用——免费套餐使用默认顺序
includeNestedComments
布尔值
comments
包含回复内容。仅付费套餐可用。每条回复视为单独结果,因此总数可能超过
resultsLimit

URL handling

URL处理

directUrls
is more forgiving than it looks. All of these are accepted:
  • Profile IDs work anywhere a profile URL does — a bare numeric ID is fine
  • instagram.com/_u/natgeo/profilecard/
    _u
    and
    profilecard
    are stripped
  • instagram.com/stories/username/
    — reduced to the username
  • instagram.com/share/BAC6cDeb_-
    — resolved to the canonical post URL
  • instagram.com/explore/locations/7538318/
    — the ID alone is valid, no slug needed
Not supported: numeric post IDs in URL form (
instagram.com/p/3369450800358839406/
) for
posts
,
reels
,
mentions
or
details
. Use the shortCode form instead. This format does work for
comments
.
The URL type drives the output schema. Hashtag, location, audio and explore URLs return their own metadata even when paired with another content mode — so a location URL with
resultsType: "details"
yields place details, not profile details.
directUrls
的容错性比看起来更强。以下格式均被接受:
  • 个人资料ID可替代个人资料URL——纯数字ID即可
  • instagram.com/_u/natgeo/profilecard/
    _u
    profilecard
    会被自动移除
  • instagram.com/stories/username/
    — 会简化为用户名
  • instagram.com/share/BAC6cDeb_-
    — 会解析为标准帖子URL
  • instagram.com/explore/locations/7538318/
    — 仅ID即可,无需slug
不支持: 用于
posts
reels
mentions
details
的数字帖子ID格式URL(
instagram.com/p/3369450800358839406/
)。请改用shortCode格式。此格式可用于
comments
URL类型决定输出schema。 话题标签、地点、音频和探索URL会返回各自的元数据,即使与其他内容模式搭配使用——例如,地点URL搭配
resultsType: "details"
会返回地点详情,而非个人资料详情。

Constraints that will bite you

需要注意的限制

  • One content type per run. There is no way to get posts and comments in a single call. Run twice.
  • URLs beat search.
    directUrls
    and
    search
    cannot be combined; if both are present the URLs win and the search is ignored.
  • Hashtags go in as plaintext
    travel
    , never
    #travel
    .
  • Multiple search terms are comma-separated in one string:
    "travel, fitness"
    .
  • Free plans get about one page of comments per post (~15). Paid plans have no such cap. Do not report this as an error — say what it is.
  • 每次运行仅支持一种内容类型。 无法在单次调用中同时获取帖子和评论。需运行两次调用。
  • URL优先级高于搜索。
    directUrls
    search
    无法同时使用;如果两者都存在,URL会优先生效,搜索参数会被忽略。
  • 话题标签需以纯文本形式传入——
    travel
    ,而非
    #travel
  • 多个搜索词以逗号分隔为单个字符串
    "travel, fitness"
  • 免费套餐每个帖子约可获取一页评论(约15条)。 付费套餐无此限制。请勿将此报告为错误——如实告知用户即可。

Common tasks

常见任务

Every capability the Actor exposes, with the payload for each. Swap the
-d '...'
into the curl above.
Profile stats for several accounts — cheapest possible call:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/","https://www.instagram.com/natgeo/"],"resultsType":"details","resultsLimit":1}'
A profile's recent posts, last 30 days:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"posts","resultsLimit":30,"onlyPostsNewerThan":"1 month"}'
A profile's reels:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"reels","resultsLimit":20}'
A profile's current stories — only returns anything while stories are live, and often needs a paid plan:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"stories","resultsLimit":20}'
Posts that mention an account — brand monitoring:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"mentions","resultsLimit":50}'
Comments on one post:
bash
-d '{"directUrls":["https://www.instagram.com/p/SHORTCODE/"],"resultsType":"comments","resultsLimit":50}'
Posts under a hashtag:
bash
-d '{"search":"wildlifephotography","searchType":"hashtag","searchLimit":50,"resultsType":"posts","resultsLimit":50}'
Find accounts by keyword
user
returns account records:
bash
-d '{"search":"climate photographer","searchType":"user","searchLimit":20,"resultsType":"details"}'
Search profiles by name
profile
matches on profile pages:
bash
-d '{"search":"national geographic","searchType":"profile","searchLimit":20,"resultsType":"details"}'
Posts from a place:
bash
-d '{"search":"Yosemite National Park","searchType":"place","searchLimit":20,"resultsType":"posts","resultsLimit":50}'
Posts from a specific location or hashtag URL — pass the URL directly instead of searching:
bash
-d '{"directUrls":["https://www.instagram.com/explore/tags/wildlife/"],"resultsType":"posts","resultsLimit":50}'
Tracking which query produced which post — when scraping several hashtags or profiles in one run,
addParentData
stamps each item with its source so the results can be grouped afterwards:
bash
-d '{"search":"wildlife","searchType":"hashtag","searchLimit":30,"resultsType":"posts","resultsLimit":30,"addParentData":true}'
Deep profile statistics — account type, post and reel counts, category, city, public contact fields. Also works on private profiles:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"details","resultsLimit":1,"addProfileStatistics":true}'
Recent posts, excluding pinned ones:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"posts","resultsLimit":30,"skipPinnedPosts":true}'
Only the pinned posts — invert the same pair:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"posts","skipPinnedPosts":false,"onlyPostsNewerThan":"0 minutes"}'
Newest comments first, including replies — both paid-plan only:
bash
-d '{"directUrls":["https://www.instagram.com/p/SHORTCODE/"],"resultsType":"comments","resultsLimit":50,"isNewestComments":true,"includeNestedComments":true}'
以下是Actor支持的所有功能及对应参数。将
-d '...'
替换到上述curl命令中即可使用。
多个账户的个人资料统计——成本最低的调用方式:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/","https://www.instagram.com/natgeo/"],"resultsType":"details","resultsLimit":1}'
个人资料的近期帖子,近30天:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"posts","resultsLimit":30,"onlyPostsNewerThan":"1 month"}'
个人资料的Reels内容:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"reels","resultsLimit":20}'
个人资料当前的快拍——仅当快拍在线时才会返回结果,通常需要付费套餐:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"stories","resultsLimit":20}'
提及该账户的帖子——品牌监测:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"mentions","resultsLimit":50}'
单条帖子的评论:
bash
-d '{"directUrls":["https://www.instagram.com/p/SHORTCODE/"],"resultsType":"comments","resultsLimit":50}'
特定话题标签下的帖子:
bash
-d '{"search":"wildlifephotography","searchType":"hashtag","searchLimit":50,"resultsType":"posts","resultsLimit":50}'
通过关键词查找账户——
user
返回账户记录:
bash
-d '{"search":"climate photographer","searchType":"user","searchLimit":20,"resultsType":"details"}'
按名称搜索个人资料——
profile
匹配个人资料页面:
bash
-d '{"search":"national geographic","searchType":"profile","searchLimit":20,"resultsType":"details"}'
特定地点的帖子:
bash
-d '{"search":"Yosemite National Park","searchType":"place","searchLimit":20,"resultsType":"posts","resultsLimit":50}'
特定地点或话题标签URL的帖子——直接传入URL而非搜索:
bash
-d '{"directUrls":["https://www.instagram.com/explore/tags/wildlife/"],"resultsType":"posts","resultsLimit":50}'
追踪每个结果对应的查询来源——当在单次运行中抓取多个话题标签或个人资料时,
addParentData
会为每个结果项添加来源信息,以便后续分组:
bash
-d '{"search":"wildlife","searchType":"hashtag","searchLimit":30,"resultsType":"posts","resultsLimit":30,"addParentData":true}'
详细个人资料统计——账户类型、帖子和Reels数量、分类、城市、公开联系字段。对私密个人资料也有效:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"details","resultsLimit":1,"addProfileStatistics":true}'
近期帖子,排除置顶帖:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"posts","resultsLimit":30,"skipPinnedPosts":true}'
仅获取置顶帖——反向设置同一参数:
bash
-d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"posts","skipPinnedPosts":false,"onlyPostsNewerThan":"0 minutes"}'
最新评论优先,包含回复内容——均为付费套餐专属:
bash
-d '{"directUrls":["https://www.instagram.com/p/SHORTCODE/"],"resultsType":"comments","resultsLimit":50,"isNewestComments":true,"includeNestedComments":true}'

Output

输出

Each content type produces a different schema, and they cannot be combined in one run. Samples below are abridged to the useful fields; the URL type you pass can override the shape (a location URL returns place data even under another mode).
Post / carousel (
resultsType: "posts"
) — 23 fields:
json
{
  "inputUrl": "https://www.instagram.com/p/DZxvMgyH8yR/",
  "id": "3923124318436838545",
  "type": "Image",
  "shortCode": "DZxvMgyH8yR",
  "caption": "In the Democratic Republic of the Congo…",
  "hashtags": [], "mentions": ["carstenpeter"],
  "url": "https://www.instagram.com/p/DZxvMgyH8yR/",
  "likesCount": 34512, "commentsCount": 210,
  "timestamp": "2026-06-22T17:24:20.000Z",
  "displayUrl": "https://…", "images": [], "childPosts": [],
  "dimensionsWidth": 1080, "dimensionsHeight": 1350, "alt": "…",
  "ownerUsername": "natgeo", "ownerFullName": "National Geographic", "ownerId": "787132",
  "firstComment": "…", "latestComments": [], "isCommentsDisabled": false
}
Reel (
resultsType: "reels"
) — 31 fields. Posts plus video:
json
{
  "…all post fields…": "…",
  "videoUrl": "https://…", "videoDuration": 28.28,
  "videoViewCount": 120433, "videoPlayCount": 98221,
  "audioUrl": "https://…", "musicInfo": {}, "productType": "clips",
  "isPinned": false
}
Comment (
resultsType: "comments"
):
json
{
  "postUrl": "https://www.instagram.com/p/DZ5T2XPllXv/",
  "commentUrl": "https://www.instagram.com/p/DZ5T2XPllXv/c/18093536360613690",
  "id": "18093536360613690",
  "text": "We love you NASA 💙🌎🌊",
  "ownerUsername": "mavideniz5521__", "ownerProfilePicUrl": "https://…",
  "timestamp": "2026-06-22T17:24:20.000Z",
  "likesCount": 4, "repliesCount": null, "replies": null,
  "owner": { "username": "…" }
}
repliesCount
and
replies
populate only with
includeNestedComments: true
(paid).
Profile details (
resultsType: "details"
) — 22 fields. Verified live:
json
{
  "inputUrl": "https://www.instagram.com/nasa/",
  "id": "528817151", "username": "nasa", "url": "https://www.instagram.com/nasa/",
  "fullName": "NASA", "biography": "Making the seemingly impossible, possible. ✨",
  "externalUrl": "https://www.nasa.gov/", "externalUrls": [],
  "followersCount": 104423132, "followsCount": 92, "postsCount": 4888,
  "verified": true, "private": false,
  "isBusinessAccount": true, "businessCategoryName": "Government Agencies",
  "joinedRecently": false, "fbid": "17841401474538262",
  "profilePicUrl": "https://…", "profilePicUrlHD": "https://…",
  "highlightReelCount": 5, "igtvVideoCount": 171,
  "latestPosts": [], "relatedProfiles": []
}
details
already includes
latestPosts
(up to 12) and
relatedProfiles
(up to 48) at no extra cost.
If the user wants a profile's numbers and a look at recent posts, one
details
call covers both — a second
posts
call is usually waste.
With
addProfileStatistics: true
a
statistics
object is appended (~60 fields):
account_type
(1 Personal, 2 Business, 3 Creator),
media_count
,
total_clips_count
,
category
,
city_name
,
address_street
,
zip
,
bio_links
,
mutual_followers_count
.
Mentions (
resultsType: "mentions"
) — 21 fields, post-shaped, plus
taggedUsers
,
music
,
carouselImages
,
carouselImageCount
.
Place details (location URL) — 16 fields:
json
{
  "inputUrl": "https://www.instagram.com/explore/locations/7538318/",
  "name": "Copenhagen, Denmark", "location_id": "7538318", "slug": "copenhagen",
  "lat": 55.6761, "lng": 12.5683,
  "location_address": "…", "location_city": "…", "location_zip": "…",
  "phone": "…", "category": "…", "price_range": "…",
  "media_count": 1284322, "ig_business": "…", "posts": [], "hours": {}
}
Hashtag details (hashtag URL) — 15 fields, including SEO-style extras:
name
,
postsCount
,
url
,
id
,
posts
,
postsPerDay
,
difficulty
,
related
,
frequent
,
average
,
rare
,
relatedFrequent
,
relatedAverage
,
relatedRare
.
Search results carry
searchTerm
and
searchSource
so you can tell which query produced each row:
  • Hashtag search — 6 fields:
    searchTerm
    ,
    searchSource
    ,
    name
    ,
    postsCount
    ,
    url
    ,
    id
  • Place search — 17 fields: place-details shape plus
    searchTerm
    /
    searchSource
  • Profile search — 13 fields: post-shaped, with
    ownerUsername
    ,
    ownerFullName
    ,
    taggedUsers
每种内容类型对应不同的schema,且无法在单次运行中混合使用。 以下示例仅保留实用字段;传入的URL类型会覆盖输出格式(例如,地点URL即使搭配其他模式也会返回地点数据)。
帖子/轮播帖
resultsType: "posts"
)——23个字段:
json
{
  "inputUrl": "https://www.instagram.com/p/DZxvMgyH8yR/",
  "id": "3923124318436838545",
  "type": "Image",
  "shortCode": "DZxvMgyH8yR",
  "caption": "在刚果民主共和国…",
  "hashtags": [], "mentions": ["carstenpeter"],
  "url": "https://www.instagram.com/p/DZxvMgyH8yR/",
  "likesCount": 34512, "commentsCount": 210,
  "timestamp": "2026-06-22T17:24:20.000Z",
  "displayUrl": "https://…", "images": [], "childPosts": [],
  "dimensionsWidth": 1080, "dimensionsHeight": 1350, "alt": "…",
  "ownerUsername": "natgeo", "ownerFullName": "National Geographic", "ownerId": "787132",
  "firstComment": "…", "latestComments": [], "isCommentsDisabled": false
}
Reel
resultsType: "reels"
)——31个字段。包含帖子的所有字段,加上视频相关字段:
json
{
  "…所有帖子字段…": "…",
  "videoUrl": "https://…", "videoDuration": 28.28,
  "videoViewCount": 120433, "videoPlayCount": 98221,
  "audioUrl": "https://…", "musicInfo": {}, "productType": "clips",
  "isPinned": false
}
评论
resultsType: "comments"
):
json
{
  "postUrl": "https://www.instagram.com/p/DZ5T2XPllXv/",
  "commentUrl": "https://www.instagram.com/p/DZ5T2XPllXv/c/18093536360613690",
  "id": "18093536360613690",
  "text": "We love you NASA 💙🌎🌊",
  "ownerUsername": "mavideniz5521__", "ownerProfilePicUrl": "https://…",
  "timestamp": "2026-06-22T17:24:20.000Z",
  "likesCount": 4, "repliesCount": null, "replies": null,
  "owner": { "username": "…" }
}
仅当设置
includeNestedComments: true
(付费套餐)时,
repliesCount
replies
才会填充数据。
个人资料详情
resultsType: "details"
)——22个字段。已验证可用:
json
{
  "inputUrl": "https://www.instagram.com/nasa/",
  "id": "528817151", "username": "nasa", "url": "https://www.instagram.com/nasa/",
  "fullName": "NASA", "biography": "让看似不可能的事成为可能。✨",
  "externalUrl": "https://www.nasa.gov/", "externalUrls": [],
  "followersCount": 104423132, "followsCount": 92, "postsCount": 4888,
  "verified": true, "private": false,
  "isBusinessAccount": true, "businessCategoryName": "Government Agencies",
  "joinedRecently": false, "fbid": "17841401474538262",
  "profilePicUrl": "https://…", "profilePicUrlHD": "https://…",
  "highlightReelCount": 5, "igtvVideoCount": 171,
  "latestPosts": [], "relatedProfiles": []
}
details
已包含
latestPosts
(最多12条)和
relatedProfiles
(最多48个),且无需额外成本。
如果用户需要个人资料数据和近期帖子预览,一次
details
调用即可满足需求——通常无需第二次
posts
调用。
设置
addProfileStatistics: true
时,会追加一个
statistics
对象(约60个字段):
account_type
(1=个人,2=企业,3=创作者)、
media_count
total_clips_count
category
city_name
address_street
zip
bio_links
mutual_followers_count
提及内容
resultsType: "mentions"
)——21个字段,类似帖子格式,加上
taggedUsers
music
carouselImages
carouselImageCount
地点详情(地点URL)——16个字段:
json
{
  "inputUrl": "https://www.instagram.com/explore/locations/7538318/",
  "name": "Copenhagen, Denmark", "location_id": "7538318", "slug": "copenhagen",
  "lat": 55.6761, "lng": 12.5683,
  "location_address": "…", "location_city": "…", "location_zip": "…",
  "phone": "…", "category": "…", "price_range": "…",
  "media_count": 1284322, "ig_business": "…", "posts": [], "hours": {}
}
话题标签详情(话题标签URL)——15个字段,包括类似SEO的额外字段:
name
postsCount
url
id
posts
postsPerDay
difficulty
related
frequent
average
rare
relatedFrequent
relatedAverage
relatedRare
搜索结果包含
searchTerm
searchSource
,以便区分每个结果对应的查询:
  • 话题标签搜索——6个字段:
    searchTerm
    searchSource
    name
    postsCount
    url
    id
  • 地点搜索——17个字段:地点详情格式加上
    searchTerm
    /
    searchSource
  • 个人资料搜索——13个字段:类似帖子格式,包含
    ownerUsername
    ownerFullName
    taggedUsers

Images are URLs, not files

图片为URL,而非文件

Every image and video field is a link to Instagram's CDN. Nothing is downloaded, and those links are signed and expire after a few hours. If the user needs the media itself, fetch it promptly on their own bandwidth.
所有图片和视频字段均为指向Instagram CDN的链接。不会下载任何文件,且这些链接已签名,几小时后会过期。如果用户需要媒体文件本身,请尽快使用自己的带宽下载。

Runs longer than a minute

运行时间超过一分钟的任务

For large jobs, start async and poll rather than holding a sync connection:
bash
RUN=$(curl -s -X POST "https://api.apify.com/v2/acts/apify~instagram-scraper/runs" \
  -H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
  -d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"posts","resultsLimit":1000}' \
  | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['id'])")

curl -s "https://api.apify.com/v2/actor-runs/$RUN?waitForFinish=60" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['status'])"

curl -s "https://api.apify.com/v2/actor-runs/$RUN/dataset/items?format=json" \
  -H "Authorization: Bearer $APIFY_TOKEN"
Poll until
status
is
SUCCEEDED
, then fetch items.
FAILED
or
ABORTED
means stop and report — do not silently retry a job the user is paying for.

对于大型任务,请启动异步调用并轮询结果,而非保持同步连接:
bash
RUN=$(curl -s -X POST "https://api.apify.com/v2/acts/apify~instagram-scraper/runs" \
  -H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
  -d '{"directUrls":["https://www.instagram.com/nasa/"],"resultsType":"posts","resultsLimit":1000}' \
  | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['id'])")

curl -s "https://api.apify.com/v2/actor-runs/$RUN?waitForFinish=60" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['status'])"

curl -s "https://api.apify.com/v2/actor-runs/$RUN/dataset/items?format=json" \
  -H "Authorization: Bearer $APIFY_TOKEN"
轮询直到
status
变为
SUCCEEDED
,然后获取结果项。如果
status
FAILED
ABORTED
,请停止并告知用户——请勿静默重试用户需要付费的任务。

Errors

错误处理

StatusMeaningWhat to do
401
Token missing, wrong, or revokedRe-run the Setup preflight above. Do not retry the call. A
401
on the curl path while the CLI is logged in means the token was invented — switch to
apify call
.
402
/
insufficient credit
Monthly credits exhaustedTell the user; they can wait for the monthly reset or upgrade at https://apify.com/pricing?fpr=z8j1nz (referral link). Do not retry.
404
Bad Actor ID or run IDCheck the URL uses
apify~instagram-scraper
with a tilde, not a slash.
408
/ timeout
Sync call exceeded the limitSwitch to the async pattern above.
Empty arrayPrivate, deleted, or genuinely emptyReport honestly. Do not assume it is a billing problem.
apify call
exits non-zero
The run failed, or the CLI session is goneThe CLI prints the reason and a run URL — read it rather than retrying. If
apify info
also fails, the session expired: re-run Setup.
An empty result is a real answer. Private accounts, deleted posts and quiet hashtags all legitimately return nothing.
状态码含义操作
401
令牌缺失、错误或已失效重新运行上述设置预检步骤。请勿重试调用。如果在curl路径下得到
401
但CLI已登录,说明令牌是伪造的——请切换到
apify call
模式。
402
/
insufficient credit
月度信用额度已耗尽告知用户;他们可以等待月度重置,或通过https://apify.com/pricing?fpr=z8j1nz(推荐链接)升级套餐。请勿重试。
404
Actor ID或运行ID错误检查URL是否使用
apify~instagram-scraper
(使用波浪号,而非斜杠)。
408
/ timeout
同步调用超时切换到上述异步模式。
空数组内容私密、已删除或确实为空如实告知用户。请勿假设是计费问题。
apify call
返回非零退出码
运行失败,或CLI会话已失效CLI会打印原因和运行URL——请查看该信息而非重试。如果
apify info
也失败,说明会话已过期:重新运行设置步骤。
空结果是真实的返回值。私密账户、已删除帖子和无内容的话题标签都会合法地返回空结果。

Data quirks to report accurately, not treat as bugs

需要准确告知用户的数据异常,而非视为错误

  • likesCount: -1
    means the creator hid the like count. Instagram does not expose it. Say "hidden by the creator" — never report it as zero or as an error.
  • Private profiles generally return nothing. One exception: if a private account is tagged as a collaborator on a post and any co-author is public, Instagram treats that post as public and it will appear in results.
  • Metrics can differ from what the app shows. Instagram serves slightly different counts to logged-out visitors, and large counts move constantly. Small discrepancies are expected.
  • Result counts are not guaranteed. There is no fixed cap; you get what Instagram exposes publicly. To sanity-check what should be available, open the URL in an incognito window.

  • likesCount: -1
    表示创作者隐藏了点赞数。Instagram不会暴露该数据。请告知用户“创作者已隐藏点赞数”——切勿报告为0或错误。
  • 私密个人资料通常不会返回任何结果。例外情况:如果私密账户作为合作者被标记在帖子中,且任何共同作者是公开账户,Instagram会将该帖子视为公开内容,会出现在结果中。
  • 指标可能与应用显示的不同。 Instagram会给未登录访客返回略微不同的计数,且大数据量计数会实时变化。小幅度差异是正常现象。
  • 结果数量不保证。 没有固定上限;您只能获取Instagram公开暴露的内容。要验证应该能获取的内容,请在隐身窗口中打开对应的URL。

Cost discipline

成本管控

The user is paying per result. Treat that as real money.
  • Always set
    resultsLimit
    .
    The default is 100 per URL; a five-URL call with the default costs 500 results when the user probably wanted 25.
  • Use
    resultsType: "details"
    for any question about followers, bio or post counts. It returns one result per profile.
  • Start small. For anything open-ended, run a bounded first pass, show the user what came back, and confirm before scaling up.
  • Say what a large run will cost before starting it. At $2.30/1,000, a 5,000-result job is about $11.50.
  • Never loop the same call after a
    401
    or
    402
    — each attempt can be billable and none of them will succeed.
用户按结果数量付费。请将其视为真实成本。
  • 请始终设置
    resultsLimit
    默认值为每个URL返回100条结果;如果用户需要25条结果,使用默认值的5个URL调用会消耗500条结果的成本。
  • 对于粉丝数、简介或帖子数量相关的查询,使用
    resultsType: "details"
    。每个个人资料仅返回1条结果。
  • 从小规模开始。 对于任何开放式请求,先运行一次有限制的调用,向用户展示返回结果,确认后再扩大规模。
  • 在启动大型任务前告知用户成本。 按每1000条结果2.30美元计算,5000条结果的任务成本约为11.50美元。
  • 在得到
    401
    402
    结果后,切勿重复调用——每次尝试都可能产生费用,且不会成功。