Youtube 数据 API CommentThreads.list:原始文本和评论线程中的显示文本显示“\u0445\u0430\u0432\u044b”

Youtube Data API CommentThreads.list: Original text and display text in comment thread showing "\u0445\u0430\u0432\u044b"

我在 Google 开发者网站上找到了一些源代码,可以帮助我通过 CommentThreads.list YouTube 数据 API 端点检索 YouTube 评论,但是当我执行该程序时,您可以在其中看到JSON 属性 dispayTextoriginalText 包含以下文本的响应:

\u0445\u0430\u0432\u044b.

(可以多种多样)

请提示我做错了什么这是代码。

import os
import json
import googleapiclient.discovery

def main():
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    DEVELOPER_KEY =*****

    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, developerKey = DEVELOPER_KEY)

    request = youtube.commentThreads().list(
        part="snippet,replies",
        videoId="8X2Eg92x0xE",
        textFormat='plainText'
    )
    response = request.execute()

    print(json.dumps(response,indent=2))

if __name__ == "__main__":
    main()

API 端点的响应是:

{
  "kind": "youtube#commentThreadListResponse",
  "etag": "EXoRH0QLHj489CmlxFtx7SfMdXs",
  "nextPageToken": "QURTSl9pM056MG5DWURxZktNbFBvU25OV01ENHNEUS03TlJBTXRtclJxdEJtbHNPaXZUYVBmWDVSZVJpZm1Hb0dlSVdWajc0aGxNV0lVRQ==",
  "pageInfo": {
    "totalResults": 20,
    "resultsPerPage": 20
  },
  "items": [
    {
      "kind": "youtube#commentThread",
      "etag": "8HgQH2sV128K2QYibRSRobFwCLw",
      "id": "UgwWhSYuhI4Dyq5xEo14AaABAg",
      "snippet": {
        "videoId": "8X2Eg92x0xE",
        "topLevelComment": {
          "kind": "youtube#comment",
          "etag": "xWiR7YCUHFOiUPTXDk9ghd_VYIA",
          "id": "UgwWhSYuhI4Dyq5xEo14AaABAg",
          "snippet": {
            "videoId": "8X2Eg92x0xE",
            "textDisplay": "\u0414\u0438\u043c\u0430 \u0432 7 \u0447\u0430\u0441\u0442\u0438 \"\u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\". \u0414\u0438\u043c\u0430 \u0432 8 \u0447\u0430\u0441\u0442\u0438 \"\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0451 \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e\"",
            "textOriginal": "\u0414\u0438\u043c\u0430 \u0432 7 \u0447\u0430\u0441\u0442\u0438 \"\u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\". \u0414\u0438\u043c\u0430 \u0432 8 \u0447\u0430\u0441\u0442\u0438 \"\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0451 \u0447\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e\"",

该代码没有任何问题。

那些是JSON Unicode escape-sequences, which encode in plain ASCII text Unicode code points

JSON 字符串 "\u0445\u0430\u0432\u044b" 被解码为 UTF-8 为 "хавы":

$ json -Pl <<< '"\u0445\u0430\u0432\u044b"'
"хавы"

$ jq <<< '"\u0445\u0430\u0432\u044b"'
"хавы"

(以上,我使用了程序 json -- 这是我自己的应用程序 Json-Type -- and jq 的一部分。)