快手(中国)
快手评论回复 API
展开快手(中国)视频下的一条评论:一级评论下的全部回复,包括回复内容、作者、IP 属地省份、回复的对象和点赞数,以 JSON 返回。每页消耗 1 积分,游标分页,count 可把每页条数设到 50。请先看视频评论接口:它已经免费附带了热门评论的前几条回复,只有映射里没有你要的评论时才需要付费调用本接口。
POST/api/v1/kuaishou/video/sub-comments
Authorizations
AuthorizationstringheaderrequiredBearer authentication header of the form Bearer <token>, where <token> is your Scavio API key (e.g. Bearer sk_live_your_key).
Body
application/jsonphoto_idstringrequired一级评论所在的快手 photo(视频)id,不能为空。必须是该评论所属的同一条视频:id 不匹配不会报错,只会返回空结果,并且照常计费。
Example: 5218546261880462502
root_comment_idstringrequired要获取回复的一级评论 id。从视频评论接口响应的 rootComments[].comment_id 中取。只有 subCommentCount 大于 0 的评论才有内容可取。
Example: 846691923381
cursorstring不透明的分页游标(cursor)。第一页不传,之后传入上一次响应中的 pcursor 值。响应字段名是 pcursor,不是 next_cursor。pcursor 为 "no_more" 表示没有更多页。
Example: V1-1006-1-eyJwaG90b0lkIjoxMzU2NTA2ODIwNTMs…
countinteger每页回复数,1 到 50(含)。不传则使用快手的默认值。超过 50 会在计费前被拒绝,返回 400。
Example: 50
Request
from scavio import ScavioClient
client = ScavioClient(api_key="sk_live_your_key")
photo_id = "5200813279900753026"
comments = client.kuaishou.video_comments(photo_id=photo_id) # 1 积分
preloaded = comments["data"].get("subCommentsMap", {})
for root in comments["data"].get("rootComments", []):
if not root.get("subCommentCount"):
continue
cid = str(root["comment_id"])
if cid in preloaded:
continue # 免费,已经拿到
cursor = None
while True:
page = client.kuaishou.comment_replies( # 每页 1 积分
photo_id=photo_id, root_comment_id=cid, cursor=cursor, count=50
)
for r in page["data"].get("subComments", []):
print(r["author_name"], "->", r.get("replyToUserName"), r["content"])
cursor = page["data"].get("pcursor") # 不是 next_cursor
if not cursor or cursor == "no_more":
breakResponse
"result": 1,
"pcursor": "no_more",
"host-name": "public-bjx-c34-kce-node938.idchb1az1.hb1.kwaidc.com"
},
"response_time": 692,
"credits_used": 1,
"credits_remaining": 4813
}