json - YouTube 视频的 liveStreamingDetails 属性是否已弃用/未实现?

标签 json youtube json.net youtube-data-api

根据谷歌的 YouTube v3 API reference documentation for the properties of a video resource ,有一个名为 liveStreamingDetails 的 JSON 对象其中应具有以下字段:

  • actualStartTime
  • actualEndTime
  • scheduledStartTime
  • scheduledEndTime
  • concurrentViewers
  • activeLiveChatId

  • 我已经根据这个结构准备了我的对象,但是当我尝试反序列化实际的 JSON snippet 时,我抛出了以下异常。来自视频 API 的响应:
  • JsonSerializationException: Error converting value "none" to type 'A1ITF.API+YouTube+LiveStreamDetails'. Path 'items[0].snippet.liveBroadcastContent', line 46, position 38.
  • ArgumentException: Could not cast or convert from System.String to A1ITF.API+YouTube+LiveStreamDetails.

  • 查看来自 API 的 JSON 响应,我完全理解错误。这是我得到的 JSON 响应(为简洁起见进行了编辑):
    {
      "kind": "youtube#videoListResponse",
      "etag": "MR2hZ6pif1LwlWdiOvdZ_4m7vDI",
      "items": [
        {
          "kind": "youtube#video",
          "etag": "hfbATXrQ1iQB2yrckDCv-dn0iiI",
          "id": "skSK9lUvqjY",
          "snippet": {
            "publishedAt": "2020-08-14T19:00:15Z",
            "channelId": "UCZGYJFUizSax-yElQaFDp5Q",
            "title": "Leia, Princess of Alderaan | The Star Wars Show Book Club",
            "description": <LONG DESCRIPTION TEXT>,
            "thumbnails": {<THUMBNAIL OBJECTS>},
            "channelTitle": "Star Wars",
            "tags": [<SEVERAL TAGS>],
            "categoryId": "24",
            "liveBroadcastContent": "none",
            "localized": {
              "title": "Leia, Princess of Alderaan | The Star Wars Show Book Club",
              "description": <LONG DESCRIPTION TEXT>
            },
            "defaultAudioLanguage": "en-US"
          }
        }
      ],
      "pageInfo": {
        "totalResults": 1,
        "resultsPerPage": 1
      }
    }
    
    异常的原因很明确:liveBroadcastContent 的值字段是单个字符串 ( "none" )。它不是上面文档中定义的对象。根据文档,我是什么 期待
    "liveBroadcastContent": 
      {
        "actualStartTime": <ISO 8601 datetime VALUE>,
        "actualEndTime": <ISO 8601 datetime VALUE>,
        "scheduledStartTime": <ISO 8601 datetime VALUE>,
        "scheduledEndTime": <ISO 8601 datetime VALUE>,
        "concurrentViewers": <unsigned long VALUE>,
        "activeLiveChatId": <string VALUE>
      },
    
    或者,如果没有任何信息可以填充 liveBroadcastContent领域
    "liveBroadcastContent": 
      {
        "actualStartTime": null,
        "actualEndTime": null,
        "scheduledStartTime": null,
        "scheduledEndTime": null,
        "concurrentViewers": null,
        "activeLiveChatId": ""
      },
    
    甚至
    "liveBroadcastContent": {},
    
    或者只是完全省略该属性与我的实际情况不符 接收
    "liveBroadcastContent": "none",
    
    我实际上一直在努力寻找一种有效的方法来有条件地反序列化这个元素,但似乎无法让它简单地返回 Nothing对于 API 返回的内容(这是另一个问题,但我仍在研究希望实现这一目标的方法)。
    我最初的测试是针对“常规”视频(不是实际的直播),所以我想我会检查一个已知的直播视频。我进入了我的 YouTube 通知,发现了几个最近有直播的专业/半专业 YouTube channel ,并选择了一个进行测试。但是,此视频的 JSON 也缺少结构化的 liveStreamingDetails对象(只有 "none" 的值)。认为这可能是“侥幸”,我检查了在我的 YouTube 通知中指定为实时流的其他一些视频,所有这些视频都显示了完全相同的结果。
    如果我将对象中该字段的定义更改为简单的 String ,一切都无一异常(exception)地反序列化,我得到一个(大部分)完全填充的对象。但是,我实际上希望为我的应用程序提供一些此类信息 - 至少要知道视频是否是/曾经是直播 - 但是 "none"显然不会告诉我太多。因此,虽然我正在努力使我的对象正确并有条件地反序列化该字段的值(我在键入此内容时提出了一些想法),但我想知道是否有人知道该字段实际上是否已实现?我基本上是在旋转我的轮子,试图让一些已经被弃用的东西工作,这是打算在 future 实现的东西,还是我只是完全密集而遗漏了一些明显的东西(一个明确而明显的可能性)?

    编辑(由接受的答案解决)
    根据接受的答案,我 完全密集。我错误地猜到了 liveBroadcastContent 字段(在 snippet 对象中)与 相同liveStreamingDetails 对象(items 集合的一部分)。如果我彻底准确地阅读了文档,我会看到前者被定义为(强调我的):

    string

    Indicates if the video is an upcoming/active live broadcast. Or it's "none" if the video is not an upcoming/active live broadcast.

    Valid values for this property are:

    • live
    • none
    • upcoming

    (在我所有的测试中显示为"none"的原因是直播已经结束)
    后者被定义为(包含在接受的答案中):

    object

    The liveStreamingDetails object contains metadata about a live video broadcast. The object will only be present in a video resource if the video is an upcoming, live, or completed live broadcast.


    此外,我的 API 请求有缺陷。当我调用正确的端点时,我实际上并没有请求填充 liveStreamingDetails 所需的信息。目的。我只是要求part=snippet当我应该请求时 part=snippet,liveStreamingDetails .

    API 请求示例:准备好的(非现场)视频
    https://www.googleapis.com/youtube/v3/videos?id=skSK9lUvqjY&part=snippet,liveStreamingDetails&key={API_KEY}
    
    退货 (为简洁起见,已编辑)
    {
      "kind": "youtube#videoListResponse",
      "etag": "MR2hZ6pif1LwlWdiOvdZ_4m7vDI",
      "items": [
        {
          "kind": "youtube#video",
          "etag": "hfbATXrQ1iQB2yrckDCv-dn0iiI",
          "id": "skSK9lUvqjY",
          "snippet": {
            "publishedAt": "2020-08-14T19:00:15Z",
            "channelId": "UCZGYJFUizSax-yElQaFDp5Q",
            "title": "Leia, Princess of Alderaan | The Star Wars Show Book Club",
            "description": <LONG DESCRIPTION TEXT>,
            "thumbnails": {<THUMBNAIL OBJECTS>},
            "channelTitle": "Star Wars",
            "tags": [<TAGS>],
            "categoryId": "24",
            "liveBroadcastContent": "none",
            "localized": {
              "title": "Leia, Princess of Alderaan | The Star Wars Show Book Club",
              "description": <LONG DESCRIPTION TEXT>
            },
            "defaultAudioLanguage": "en-US"
          }
        }
      ],
      "pageInfo": {
        "totalResults": 1,
        "resultsPerPage": 1
      }
    }
    

    API 请求示例:直播
    https://www.googleapis.com/youtube/v3/videos?id=RX4vy_M-NS8&part=snippet,liveStreamingDetails&key={API_KEY}
    
    退货 (为简洁起见,已编辑)
    {
      "kind": "youtube#videoListResponse",
      "etag": "Aq44bdQmbZxoLEp0SOJh4xW0PSE",
      "items": [
        {
          "kind": "youtube#video",
          "etag": "9TVc3oB01vQME2QsvEJcaRueEqc",
          "id": "RX4vy_M-NS8",
          "snippet": {
            "publishedAt": "2020-08-20T18:50:20Z",
            "channelId": "UCRTQL0CmZjHlvPy5nLZ1Gfg",
            "title": "Starting a new character in Star Wars: The Old Republic [Live Stream Recorded on August 20, 2020]",
            "description": <LONG DESCRIPTION TEXT>,
            "thumbnails": {<THUMBNAIL OBJECTS>},
            "channelTitle": "HelloGreedo",
            "tags": [<TAGS>],
            "categoryId": "1",
            "liveBroadcastContent": "none",
            "localized": {
              "title": "Starting a new character in Star Wars: The Old Republic [Live Stream Recorded on August 20, 2020]",
              "description": <LONG DESCRIPTION TEXT>
            }
          },
          "liveStreamingDetails": {
            "actualStartTime": "2020-08-20T17:04:45Z",
            "actualEndTime": "2020-08-20T18:41:23Z"
          }
        }
      ],
      "pageInfo": {
        "totalResults": 1,
        "resultsPerPage": 1
      }
    }
    
    在更正我的 API 请求并将适当的属性添加到我准备好的代码对象后,我想要的一切都完全按预期/希望的那样完成。

    最佳答案

    根据您已经引用的文档:

    liveStreamingDetails (object)

    The liveStreamingDetails object contains metadata about a live video broadcast. The object will only be present in a video resource if the video is an upcoming, live, or completed live broadcast.


    因此,对象 liveStreamingDetails 是非常合法的。从 Videos.list 获得的视频资源 JSON 响应中丢失API 端点。
    liveStreamingDetails对象根本没有被弃用。在以下直播中亲自查看 Deutsche Welle News Livestream :
    只需调用 Videos.list以下 URL 上的端点(将 $APP_KEY 替换为您的应用程序 key ):https://www.googleapis.com/youtube/v3/videos?key=$APP_KEY&id=NvqKZHpKs-g&part=contentDetails,id,liveStreamingDetails,player,recordingDetails,snippet,statistics,status,topicDetails用于获取以下 JSON 响应文本:
    {
        "kind": "youtube#videoListResponse",
        "etag": "LmFuBTaRf4C5sL3aRpTmKefaXnw",
        "items": [
            {
                "kind": "youtube#video",
                "etag": "5nm5pG-Kto-dPRTqwcnFKQxf3UU",
                "id": "NvqKZHpKs-g",
                "snippet": {
                    "publishedAt": "2019-01-21T13:21:24Z",
                    "channelId": "UCknLrEdhRCp1aegoMqRaCZg",
                    "title": "DW News Livestream | Latest news and breaking stories",
                    "description": "DW News goes deep beneath the surface, providing the key stories from Europe and around the world.\n\nExciting reports and interviews from the worlds of politics, business, sports, culture and social media are presented by our DW anchors in 15-, 30- and 60-minute shows.\n\nCorrespondents on the ground and experts in the studio deliver detailed insights and analysis of issues that affect our viewers around the world. We combine our expertise on Germany and Europe with a special interest in Africa and Asia while keeping track of stories from the rest of the world.\n\nInformative, entertaining and up-to-date – DW News, connecting the dots for our viewers across the globe.\n\nDeutsche Welle is Germany’s international broadcaster. We convey a comprehensive image of Germany, report events and developments, incorporate German and other perspectives in a journalistically independent manner. By doing so we promote understanding between cultures and peoples.\n\n#dwNews #LiveNews #NewsToday",
                    "thumbnails": {
                        ...
                    },
                    "channelTitle": "DW News",
                    "tags": [
                        "dw news",
                        "live news",
                        "breaking news",
                        "news tv",
                        "live tv",
                        "news today",
                        "deutsche welle",
                        "deutsche welle news",
                        "nive news tv",
                        "tv live news",
                        "daily news"
                    ],
                    "categoryId": "25",
                    "liveBroadcastContent": "live",
                    "localized": {
                        "title": "DW News Livestream | Latest news and breaking stories",
                        "description": "DW News goes deep beneath the surface, providing the key stories from Europe and around the world.\n\nExciting reports and interviews from the worlds of politics, business, sports, culture and social media are presented by our DW anchors in 15-, 30- and 60-minute shows.\n\nCorrespondents on the ground and experts in the studio deliver detailed insights and analysis of issues that affect our viewers around the world. We combine our expertise on Germany and Europe with a special interest in Africa and Asia while keeping track of stories from the rest of the world.\n\nInformative, entertaining and up-to-date – DW News, connecting the dots for our viewers across the globe.\n\nDeutsche Welle is Germany’s international broadcaster. We convey a comprehensive image of Germany, report events and developments, incorporate German and other perspectives in a journalistically independent manner. By doing so we promote understanding between cultures and peoples.\n\n#dwNews #LiveNews #NewsToday"
                    },
                    "defaultAudioLanguage": "en"
                },
                "contentDetails": {
                    "duration": "P0D",
                    "dimension": "2d",
                    "definition": "sd",
                    "caption": "false",
                    "licensedContent": false,
                    "contentRating": {
                    },
                    "projection": "rectangular"
                },
                "status": {
                    "uploadStatus": "uploaded",
                    "privacyStatus": "public",
                    "license": "youtube",
                    "embeddable": true,
                    "publicStatsViewable": true,
                    "madeForKids": false
                },
                "statistics": {
                    "viewCount": "17086181",
                    "likeCount": "49865",
                    "dislikeCount": "6539",
                    "favoriteCount": "0",
                    "commentCount": "0"
                },
                "player": {
                    "embedHtml": "<iframe width=\"480\" height=\"270\" src=\"//www.youtube.com/embed/NvqKZHpKs-g\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"
                },
                "topicDetails": {
                    "relevantTopicIds": [
                        "/m/019_rr",
                        "/m/07c1v",
                        "/m/019_rr",
                        "/m/07c1v"
                    ],
                    "topicCategories": [
                        "https://en.wikipedia.org/wiki/Lifestyle_(sociology)",
                        "https://en.wikipedia.org/wiki/Technology"
                    ]
                },
                "recordingDetails": {
                },
                "liveStreamingDetails": {
                    "actualStartTime": "2019-01-21T13:33:28Z",
                    "concurrentViewers": "712"
                }
            }
        ],
        "pageInfo": {
            "totalResults": 1,
            "resultsPerPage": 1
        }
    }
    

    关于json - YouTube 视频的 liveStreamingDetails 属性是否已弃用/未实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63525784/

    相关文章:

    php - 全日历 PHP mysql JSON

    javascript - D3 映射与 geoJson 美国 map 工作但不工作世界

    php - 嵌入的YouTube URL

    c# - 如何跳过 Json.Net 中 IEnumerable 类型的默认 JavaScript 数组序列化?

    json - Gatling JSON Feeder 独特的 POST 机构

    php - Instagram 实时更新标签 - 获取空数据,为什么?

    c# - 如何使用 Json.NET StringEscapeHandling.EscapeNonAscii

    c# - 如何在 Elasticsearch NEST 中序列化 JToken 或 JObject 类型的属性?

    youtube - YouTube API V3注释线程不适用于访问 token

    javascript - 如何混合javascript和meteor来使用youtube api