如何检索待审核的 YouTube 评论



我正在尝试检索所有保留以供审查的评论。我能够使用 commentThreads((.list(( 函数获取顶级评论,但需要获取对保留以供审查的顶级评论的回复。我使用 comments((.list(( 方法来获取对顶级评论的回复。我能够得到回复,但所有这些都是已发布的评论。所有待审查的评论都没有被检索到,这令人费解。这是应该的吗?我不需要已发布的评论,我只需要那些被保留以供审查的评论。我试图请求保留以供审核的评论,但不断收到以下错误:

mod     = item['snippet']['moderationStatus']
KeyError: 'moderationStatus'

不知道该怎么做才能获得等待审查的依赖。


def get_comments(service, parent_id, threadId, comments):
results = service.comments().list(
part                = "snippet, id",
parentId            = parent_id,
textFormat          = "plainText"
).execute()
for item in results['items']:
cid     = item['id']
text    = item['snippet']['textDisplay']
mod     = item['snippet']['moderationStatus']  
# ^ The line above generates an error: KeyError: 'moderationStatus'
# If I delete the "mod =..." and the "if mod !=..." lines, I get all 
# of the replies to the top-level comment (parentId) that have been 
# published but none of the ones that are held for review. 
if mod != "heldForReview":
comments.append([text, cid])
return comments

有一个查询参数moderationStatus可用于获取保留以供审阅的评论。我认为您只需要设置moderationStatus= heldForReview

在此处查看文档 https://developers.google.com/youtube/v3/docs/commentThreads/

您的查询将如下所示

curl 
'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&moderationStatus=heldForReview&videoId=[VIDEO_ID]&key=[YOUR_API_KEY]' 
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' 
--header 'Accept: application/json' 
--compressed

最新更新