设计与多媒体

Instagram

通过 Instagram Graph API 管理 Instagram 账号:查看资料、发布图文与 Reels、处理评论。

它能做什么

封装 Instagram Graph API 的账号管理工具,支持查看资料(昵称、用户名、账号类型、帖子数)、列出与查看帖子、发布单图或多图轮播(最多 10 张)、发布 Reels 或视频轮播,以及评论的读取与回复。每次命令执行前会自动刷新 token。本地文件上传会临时开启 cloudflared Quick Tunnel,完成后立即关闭。所有输出均为 JSON 格式。

什么时候用它

  • 查看账号资料与帖子数量
  • 发布单张图片或多图轮播帖子
  • 发布 Reel 视频并指定封面与缩略图偏移
  • 读取帖子评论并进行回复

技能文档

Instagram API Skill

A skill for managing an Instagram account via the Instagram Graph API. Supports profile viewing, post management, image publishing, video/Reels publishing, and comment operations.

Prerequisites

  • A .env file with credentials must be configured.
    • Required: INSTAGRAM_ACCESS_TOKEN
    • Recommended (for comment/reply via Facebook Graph): FACEBOOK_USER_ACCESS_TOKEN
    • Required for FB token refresh: FACEBOOK_APP_ID, FACEBOOK_APP_SECRET
  • cloudflared must be installed for local image/video posting.
  • If the user specifies a .env file path, append --env to every command.
    • Example: node scripts/get-profile.js --env /home/user/.instagram-env
  • All scripts must be run with this project root as the working directory.

Available Commands

All commands automatically refresh the token before execution. No manual refresh needed.

Refresh Token

# Instagram token refresh
node scripts/refresh-token.js

# Facebook user token refresh (for comments/replies flow)
node scripts/refresh-facebook-token.js

Manually refreshes token(s) and returns expiration info.

View Profile

node scripts/get-profile.js

Returns profile info (name, username, account type, media count).

List Posts

node scripts/get-posts.js [--limit 10]

Returns the user's post list. Use --limit to set the count (default: 10).

View Post Detail

node scripts/get-post.js 

Returns post detail including like count and comment count.

Publish Image

# Single image (URL)
node scripts/post-image.js --caption "Caption" https://example.com/photo.jpg

# Single image (local file)
node scripts/post-image.js --caption "Caption" ./photos/image.png

# Carousel — multiple images (URL)
node scripts/post-image.js --caption "Caption" https://example.com/a.jpg https://example.com/b.jpg

# Carousel — multiple images (local files)
node scripts/post-image.js --caption "Caption" ./img1.png ./img2.png ./img3.jpg
  • 1 image → single post, 2+ images → automatically posted as carousel (max 10).
  • Both URLs (http://, https://) and local file paths are supported, but mixing is not allowed.
  • Supported local file formats: jpg, jpeg, png, gif, webp, heic/heif (HEIC is automatically converted to JPEG).

Publish Video (Reels)

# Single video (URL)
node scripts/post-video.js --caption "Caption" https://example.com/video.mp4

# Single video (local file)
node scripts/post-video.js --caption "Caption" ./videos/clip.mp4

# With cover image and options
node scripts/post-video.js --caption "Caption" --cover https://example.com/cover.jpg --thumb-offset 5000 --share-to-feed true https://example.com/video.mp4

# Video carousel — multiple videos (URL)
node scripts/post-video.js --caption "Caption" https://example.com/a.mp4 https://example.com/b.mp4

# Video carousel — multiple videos (local files)
node scripts/post-video.js --caption "Caption" ./clip1.mp4 ./clip2.mov
  • 1 video → Reels post, 2+ videos → automatically posted as carousel (max 10).
  • Both URLs and local file paths are supported, but mixing is not allowed.
  • Supported formats: mp4, mov (max 100MB per file).
  • --cover, --thumb-offset, --share-to-feed options are only available for single video posts (not carousels).
  • Video processing takes longer than images; the script waits up to 10 minutes.

View Comments

node scripts/get-comments.js 

Returns comments and replies for a specific post.

Post Comment

node scripts/post-comment.js  --text "Comment text"

Reply to Comment

node scripts/reply-comment.js  --text "Reply text"

Workflow Guidelines

  • When publishing images or videos, always confirm the caption with the user before executing.
  • After publishing, report the result ID and permalink to the user (both are included in the output).
  • Video processing takes longer than images. Inform the user that it may take a few minutes.
  • When writing comments/replies, confirm the content with the user before executing.
  • All command outputs are in JSON format.

Error Handling

If the output contains an error field, an error has occurred. Explain the cause to the user and suggest a resolution.

{ "error": "error message" }

Security

Token storage

  • refreshIgToken() and refreshFbToken() overwrite tokens in the .env file in plaintext. Do not commit .env to version control.
  • Create a dedicated Meta app with minimum required permissions (see below).

Local file upload

  • Local image/video posting starts a temporary cloudflared Quick Tunnel to expose files so Instagram servers can download them.
  • The tunnel is active only during the upload and is shut down immediately after.
  • Only provide file paths you are comfortable briefly exposing to the internet.

Minimum required permissions

When creating your Meta app, grant only these permissions:

  • instagram_business_basic — profile and media read
  • instagram_content_publish — image/video publishing
  • instagram_manage_comments — comment read/write
  • pages_read_engagement — required for comment API via Facebook Graph
  • pages_show_list — required for page-linked Instagram accounts

常见问题

需要准备哪些凭证?
必填 INSTAGRAM_ACCESS_TOKEN;评论与回复还需要 FACEBOOK_USER_ACCESS_TOKEN,以及用于刷新 Facebook token 的 FACEBOOK_APP_ID 和 FACEBOOK_APP_SECRET。本地文件发布还需安装 cloudflared。
支持哪些图片和视频格式?
图片支持 jpg、jpeg、png、gif、webp、heic/heif(HEIC 会自动转换为 JPEG);视频支持 mp4、mov,单个文件最大 100MB。轮播最多 10 项,URL 与本地路径不可混用。
本地文件如何上传到 Instagram?
脚本会临时启动一个 cloudflared Quick Tunnel 将文件暴露给 Instagram 服务器,上传完成后立即关闭。仅向脚本提供你愿意短暂暴露到公网的本地文件路径。

相关技能

通过 AdaptlyPost API 在 9 个社交平台调度、起草或发布帖子,发布前需用户逐项确认。

97 次安装3 星标

通过一条提示词生成 Instagram 与 TikTok 视频、轮播图与帖子。

160 次安装20 星标

通过 PostFast API 在 11 个平台定时发布社交内容,支持文案、图文视频、草稿、数据与粉丝数据。

117 次安装8 星标

通过托管 OAuth 调用 LinkedIn REST API,覆盖发文、个人资料、广告账户与广告库。

410 次安装45 星标

通过 OpenTweet REST API 在 X 上发推、排程、发布线程与长文,并附带 AI 生成的图片与视频。

84 次安装2 星标