介绍
# gram 📸
使用 REST/GraphQL API + cookie 认证的 Instagram CLI 工具。
## 安装
```bash # npm/pnpm/bun npm install -g @cyberdrk/gram
# One-shot (no install) bunx @cyberdrk/gram whoami ```
## 身份验证
`gram` 使用来自 Instagram 网页会话的基于 Cookie 的身份验证。
使用 `--session-id`、`--csrf-token` 和 `--ds-user-id` 直接传递 Cookie,或使用 `--cookie-source` 获取浏览器 Cookie。
运行 `gram check` 查看当前激活的源。对于 Arc/Brave,请使用 `--chrome-profile-dir <path>`。
## 命令
### 账户与身份验证
```bash gram whoami # Show logged-in account gram check # Show credential sources gram query-ids --refresh # Refresh GraphQL query ID cache ```
### 读取帖子
```bash gram post <shortcode-or-url> # View a post gram <shortcode-or-url> # Shorthand for post gram comments <shortcode> -n 20 # View comments on a post gram likers <shortcode> # View users who liked a post ```
### 动态流
```bash gram feed -n 20 # Home feed gram explore -n 20 # Explore/discover feed ```
### 用户资料
```bash gram user <username> # View user profile gram user @instagram --json # JSON output gram posts <username> -n 20 # User's posts gram following [username] # Users someone follows (defaults to you) gram followers [username] # Someone's followers (defaults to you) ```
### 搜索
```bash gram search "query" # Search users, hashtags, places gram search "coffee" --type users gram search "nyc" --type places gram search "#photography" --type hashtags ```
### 互动操作
```bash gram like <shortcode> # Like a post gram unlike <shortcode> # Unlike a post gram save <shortcode> # Save/bookmark a post gram unsave <shortcode> # Unsave a post gram comment <shortcode> "nice!" # Comment on a post gram follow <username> # Follow a user gram unfollow <username> # Unfollow a user ```
## 输出选项
```bash --json # JSON output --json-full # JSON with raw API response in _raw field --plain # No emoji, no color (script-friendly) --no-emoji # Disable emoji --no-color # Disable ANSI colors (or set NO_COLOR=1) ```
## 全局选项
```bash --session-id <token> # Instagram sessionid cookie --csrf-token <token> # Instagram csrftoken cookie --ds-user-id <id> # Instagram ds_user_id cookie --cookie-source <source> # Cookie source for browser cookies (repeatable) --chrome-profile <name> # Chrome profile name --chrome-profile-dir <path> # Chrome/Chromium profile dir or cookie DB path --firefox-profile <name> # Firefox profile --timeout <ms> # Request timeout --cookie-timeout <ms> # Cookie extraction timeout ```
## 配置文件
`~/.config/gram/config.json5` (全局) 或 `./.gramrc.json5` (项目):
```json5 { cookieSource: ["safari", "chrome"], chromeProfile: "Profile 1", timeoutMs: 60000 } ```
环境变量: `GRAM_TIMEOUT_MS`, `GRAM_COOKIE_TIMEOUT_MS`
## 故障排除
### Query IDs 过期 (404 错误) ```bash gram query-ids --refresh ```
### Cookie 提取失败 - 检查浏览器是否已登录 Instagram - 尝试不同的 `--cookie-source` - 对于 Arc/Brave:使用 `--chrome-profile-dir` - 手动提供 Cookie:`--session-id`、`--csrf-token`、`--ds-user-id`
### User-agent 不匹配错误 - CLI 默认使用桌面 User-agent - 如果您的会话是在移动设备上创建的,可能会失败 - 通过桌面浏览器登录来创建新会话
---
**TL;DR**: 通过 CLI 查看动态流、资料、搜索并与 Instagram 进行互动。 📸