TikTok manager: post videos, list content & check account stats. Requires: powershell/pwsh. Reads ~/.config/tiktok-page/credentials.json (TIKTOK_ACCESS_TOKEN, TIKTOK_REFRESH_TOKEN, TIKTOK_CLIENT_KEY, TIKTOK_CLIENT_SECRET, TIKTOK_OPEN_ID). Tokens expire every 24h — auto-refresh via TIKTOK_REFRESH_TOKEN. Grant minimal permissions only. Rotate immediately if host is compromised. No data forwarded; all calls go to open.tiktokapis.com only.
根据用户需求,内联构建并执行 TikTok API 调用。无需脚本。
API 基础 URL:https://open.tiktokapis.com/v2
凭据存储在 ~/.config/tiktok-page/credentials.json 中。
powershell
$cfg = Get-Content $HOME/.config/tiktok-page/credentials.json -Raw | ConvertFrom-Json
$accessToken = $cfg.TIKTOKACCESSTOKEN
$refreshToken = $cfg.TIKTOKREFRESHTOKEN
$clientKey = $cfg.TIKTOKCLIENTKEY
$clientSecret = $cfg.TIKTOKCLIENTSECRET
$openId = $cfg.TIKTOKOPENID
如果文件不存在,请引导设置:
| 字段 | 用途 |
|---|---|
| TIKTOKACCESSTOKEN | OAuth2 访问令牌 — 用于所有 API 调用 |
| TIKTOKREFRESHTOKEN |
一次性 OAuth2 设置:
powershell
$body = clientkey=$clientKey&clientsecret=$clientSecret&code=$code&granttype=authorizationcode&redirect_uri=$redirectUri
$r = Invoke-RestMethod https://open.tiktokapis.com/v2/oauth/token/ -Method POST
-Headers @{ Content-Type = application/x-www-form-urlencoded } -Body $body -ErrorAction Stop
New-Item -ItemType Directory -Force -Path $HOME/.config/tiktok-page | Out-Null
@{
TIKTOKACCESSTOKEN = $r.access_token
TIKTOKREFRESHTOKEN = $r.refresh_token
TIKTOKCLIENTKEY = $clientKey
TIKTOKCLIENTSECRET = $clientSecret
TIKTOKOPENID = $r.open_id
} | ConvertTo-Json | Set-Content $HOME/.config/tiktok-page/credentials.json -Encoding UTF8
保存后立即限制文件权限:
powershell
切勿将此文件提交到版本控制。它包含长期有效的密钥。
此技能仅向 open.tiktokapis.com 发出外部调用。不会将数据转发给第三方。
TikTok 访问令牌在 24 小时后过期。如有需要,在调用前刷新:
powershell
$cfg = Get-Content $HOME/.config/tiktok-page/credentials.json -Raw | ConvertFrom-Json
$body = clientkey=$($cfg.TIKTOKCLIENTKEY)&clientsecret=$($cfg.TIKTOKCLIENTSECRET)&granttype=refreshtoken&refreshtoken=$($cfg.TIKTOKREFRESH_TOKEN)
$r = Invoke-RestMethod https://open.tiktokapis.com/v2/oauth/token/ -Method POST
-Headers @{ Content-Type = application/x-www-form-urlencoded } -Body $body -ErrorAction Stop
$cfg.TIKTOKACCESSTOKEN = $r.access_token
$cfg.TIKTOKREFRESHTOKEN = $r.refresh_token
$cfg | ConvertTo-Json | Set-Content $HOME/.config/tiktok-page/credentials.json -Encoding UTF8
Write-Host 令牌已刷新。
| 用户需求 | 方法 | 端点 |
|---|---|---|
| 获取账户信息 | POST | /user/info/ |
| 列出自己的视频 |
GET 账户信息:
powershell
$cfg = Get-Content $HOME/.config/tiktok-page/credentials.json -Raw | ConvertFrom-Json
$headers = @{ Authorization = Bearer $($cfg.TIKTOKACCESSTOKEN); Content-Type = application/json; charset=UTF-8 }
$body = @{ fields = displayname,avatarurl,followercount,followingcount,likescount,videocount } | ConvertTo-Json
$result = Invoke-RestMethod https://open.tiktokapis.com/v2/user/info/ -Method POST -Headers $headers -Body $body -ErrorAction Stop
$result.data.user
列出视频:
powershell
$cfg = Get-Content $HOME/.config/tiktok-page/credentials.json -Raw | ConvertFrom-Json
$headers = @{ Authorization = Bearer $($cfg.TIKTOKACCESSTOKEN); Content-Type = application/json; charset=UTF-8 }
$body = @{ maxcount = 20; fields = id,title,createtime,coverimageurl,shareurl,viewcount,likecount,commentcount,share_count } | ConvertTo-Json
$result = Invoke-RestMethod https://open.tiktokapis.com/v2/video/list/ -Method POST -Headers $headers -Body $body -ErrorAction Stop
$result.data.videos | Format-Table id, title, viewcount, likecount, create_time
按 ID 获取视频详情:
powershell
$cfg = Get-Content $HOME/.config/tiktok-page/credentials.json -Raw | ConvertFrom-Json
$headers = @{ Authorization = Bearer $($cfg.TIKTOKACCESSTOKEN); Content-Type = application/json; charset=UTF-8 }
$body = @{ filters = @{ videoids = @(
从 URL 发布视频:
powershell
$cfg = Get-Content $HOME/.config/tiktok-page/credentials.json -Raw | ConvertFrom-Json
$headers = @{ Authorization = Bearer $($cfg.TIKTOKACCESSTOKEN); Content-Type = application/json; charset=UTF-8 }
$body = @{
post_info = @{
title = 你的视频标题
privacylevel = PUBLICTO_EVERYONE
disable_duet = $false
disable_stitch = $false
disable_comment = $false
}
source_info = @{
source = PULLFROMURL
video_url = https://example.com/video.mp4
video_size = 12345678
chunk_size = 10000000
totalchunkcount = 1
}
} | ConvertTo-Json -Depth 5
$result = Invoke-RestMethod https://open.tikt
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 tiktok-page-1776287724 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 tiktok-page-1776287724 技能
skillhub install tiktok-page-1776287724
文件大小: 4.42 KB | 发布时间: 2026-4-16 17:36