vk

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Call the VK API with
curl + jq
. The token is injected as
$VK_ACCESS_TOKEN
and is passed in the
Authorization: Bearer
header. Every VK API call also requires the
v
(API version) query parameter — use
v=5.199
. Base URL:
https://api.vk.com/method/<method>
.
VK always returns HTTP 200; success is
{"response": ...}
and failure is
{"error":{"error_code":<n>,"error_msg":"<detail>"}}
— always check for
.error
and show
error_msg
verbatim. Common codes:
5
= auth failed (token wrong or revoked → user must re-connect the VK connector),
214
= access to adding post denied (the token lacks the
wall
right — a community access key with
wall
is required),
15
/
203
= access denied to that owner.
使用
curl + jq
调用VK API。令牌以
$VK_ACCESS_TOKEN
的形式注入,并通过
Authorization: Bearer
头传递。每一次VK API调用都需要
v
(API版本)查询参数——请使用
v=5.199
。基础URL为:
https://api.vk.com/method/<method>
VK始终返回HTTP 200状态码;成功时返回
{"response": ...}
,失败时返回
{"error":{"error_code":<n>,"error_msg":"<detail>"}}
——务必检查
.error
字段,并原样显示
error_msg
内容。常见错误码:
5
= 认证失败(令牌错误或已撤销 → 用户必须重新连接VK连接器),
214
= 发布帖子权限被拒绝(令牌缺少
wall
权限 —— 需要带有
wall
权限的社区访问密钥),
15
/
203
= 对该所有者的访问被拒绝。

Step 1 — identify who you can post as

步骤1 — 确定发帖身份

A community access key posts on the community wall:
owner_id
must be the negative community id and you pass
from_group=1
. Resolve the community id from the token:
bash
curl -sS "https://api.vk.com/method/groups.getById?v=5.199" \
  -H "Authorization: Bearer $VK_ACCESS_TOKEN" \
  | jq '.response, .error'
Take the group
id
(e.g.
123456
) →
owner_id
is
-123456
. (For a personal user token,
owner_id
is your positive user id from
users.get
, and you omit
from_group
.)
使用社区访问密钥将发布到社区墙:
owner_id
必须为负数形式的社区ID,并且需要传递
from_group=1
参数。通过令牌解析社区ID:
bash
curl -sS "https://api.vk.com/method/groups.getById?v=5.199" \
  -H "Authorization: Bearer $VK_ACCESS_TOKEN" \
  | jq '.response, .error'
获取群组
id
(例如
123456
)→
owner_id
即为
-123456
。(如果是个人用户令牌,
owner_id
是通过
users.get
获取的正数用户ID,并且不需要传递
from_group
参数。)

Post to the wall

发布帖子到墙

Confirm the message text with the user before posting. The post must have text and/or attachments.
bash
OWNER_ID="-123456"   # negative = community; from_group=1 posts as the community
MSG="Пример поста через VK API. #ai"
curl -sS -G "https://api.vk.com/method/wall.post" \
  -H "Authorization: Bearer $VK_ACCESS_TOKEN" \
  --data-urlencode "v=5.199" \
  --data-urlencode "owner_id=$OWNER_ID" \
  --data-urlencode "from_group=1" \
  --data-urlencode "message=$MSG" \
  | jq '.response, .error'
Success returns
{"response":{"post_id":<id>}}
. The public URL is
https://vk.com/wall<OWNER_ID>_<post_id>
(e.g.
https://vk.com/wall-123456_17
).
  • Hashtags (
    #tag
    ) and plain URLs in
    message
    are rendered/clickable natively — no facet/offset handling needed (unlike Bluesky).
  • Attach media/links with
    attachments
    (comma-separated), format
    {type}{owner_id}_{media_id}
    (e.g.
    photo-123456_789
    ) or a single external URL. Only one link may be attached; more than one link → error 222.
  • publish_date
    (Unix timestamp) schedules a deferred post.
  • Always send Cyrillic
    message
    via
    --data-urlencode
    so it isn't mangled.
**发帖前请与用户确认消息文本。**帖子必须包含文本和/或附件。
bash
OWNER_ID="-123456"   # 负数代表社区;from_group=1表示以社区身份发帖
MSG="Пример поста через VK API. #ai"
curl -sS -G "https://api.vk.com/method/wall.post" \
  -H "Authorization: Bearer $VK_ACCESS_TOKEN" \
  --data-urlencode "v=5.199" \
  --data-urlencode "owner_id=$OWNER_ID" \
  --data-urlencode "from_group=1" \
  --data-urlencode "message=$MSG" \
  | jq '.response, .error'
成功时返回
{"response":{"post_id":<id>}}
。公开URL为
https://vk.com/wall<OWNER_ID>_<post_id>
(例如
https://vk.com/wall-123456_17
)。
  • 消息中的话题标签(
    #tag
    )和普通URL会被原生渲染为可点击状态——无需处理facet/offset(与Bluesky不同)。
  • 使用
    attachments
    参数(逗号分隔)添加媒体/链接,格式为
    {type}{owner_id}_{media_id}
    (例如
    photo-123456_789
    )或单个外部URL。仅允许添加一个链接;添加多个链接会返回错误码222。
  • publish_date
    (Unix时间戳)用于设置定时发布的帖子。
  • 发送西里尔文消息时务必使用
    --data-urlencode
    ,避免乱码。

List my recent wall posts + engagement

列出我的近期墙帖及互动数据

bash
OWNER_ID="-123456"
curl -sS -G "https://api.vk.com/method/wall.get" \
  -H "Authorization: Bearer $VK_ACCESS_TOKEN" \
  --data-urlencode "v=5.199" \
  --data-urlencode "owner_id=$OWNER_ID" \
  --data-urlencode "count=20" \
  | jq '.error, (.response.items[]? | {id,
        text,
        likes: .likes.count,
        reposts: .reposts.count,
        comments: .comments.count,
        views: .views.count,
        date})'
count
max 100. Combine
owner_id
+ a post
id
to build the URL
https://vk.com/wall<owner_id>_<id>
.
bash
OWNER_ID="-123456"
curl -sS -G "https://api.vk.com/method/wall.get" \
  -H "Authorization: Bearer $VK_ACCESS_TOKEN" \
  --data-urlencode "v=5.199" \
  --data-urlencode "owner_id=$OWNER_ID" \
  --data-urlencode "count=20" \
  | jq '.error, (.response.items[]? | {id,
        text,
        likes: .likes.count,
        reposts: .reposts.count,
        comments: .comments.count,
        views: .views.count,
        date})'
count
参数最大值为100。将
owner_id
与帖子
id
组合即可构建帖子URL:
https://vk.com/wall<owner_id>_<id>

Delete a post

删除帖子

bash
OWNER_ID="-123456"; POST_ID="17"
curl -sS -G "https://api.vk.com/method/wall.delete" \
  -H "Authorization: Bearer $VK_ACCESS_TOKEN" \
  --data-urlencode "v=5.199" \
  --data-urlencode "owner_id=$OWNER_ID" \
  --data-urlencode "post_id=$POST_ID" \
  | jq '.response, .error'
bash
OWNER_ID="-123456"; POST_ID="17"
curl -sS -G "https://api.vk.com/method/wall.delete" \
  -H "Authorization: Bearer $VK_ACCESS_TOKEN" \
  --data-urlencode "v=5.199" \
  --data-urlencode "owner_id=$OWNER_ID" \
  --data-urlencode "post_id=$POST_ID" \
  | jq '.response, .error'

Gotchas

注意事项

  • v
    is mandatory
    on every call — omitting it returns an error.
  • User tokens can't be freshly minted via OAuth (Implicit / Authorization Code flows for user tokens were disabled 2024-06); use a community access key (unlimited lifetime, created in the community's API settings) with the
    wall
    right.
  • Posting as the community requires both
    owner_id
    negative and
    from_group=1
    .
  • Rate/anti-spam: repeated identical posts or too-frequent posting can hit codes like
    214
    /
    219
    — space posts out.
  • v
    参数是必填项
    ——每次调用都必须包含,否则会返回错误。
  • 无法通过OAuth新生成用户令牌(用户令牌的隐式/授权码流程已于2024年6月禁用);请使用带有
    wall
    权限的社区访问密钥(无有效期限制,可在社区API设置中创建)。
  • 以社区身份发帖时,必须同时设置
    owner_id
    为负数传递
    from_group=1
    参数。
  • 频率/反垃圾机制:重复发布相同内容或发帖过于频繁可能会触发
    214
    /
    219
    等错误码——请间隔发帖。