Getting title and description of embedded YouTube video

后端 未结 7 1818
抹茶落季
抹茶落季 2021-02-05 12:36

On a site I\'m developing I embed videos from YouTube and want to get the video title and its description.

How do I get that information?

7条回答
  •  梦谈多话
    2021-02-05 12:58

    GData is deprecated, but one can still get the video description by calling this endpoint:

    https://www.googleapis.com/youtube/v3/videos?part=snippet&id=[video_id]&key=[api_key]

    It will return a response of the form:

    {
     "kind": "youtube#videoListResponse",
     "etag": "\"...\"",
     "pageInfo": {
      "totalResults": 1,
      "resultsPerPage": 1
     },
     "items": [
      {
       "kind": "youtube#video",
       "etag": "\"...\"",
       "id": "...",
       "snippet": {
        "publishedAt": "...",
        "channelId": "...",
        "title": "...",
        "description": "...",
        "thumbnails": { ... },
        "channelTitle": "...",
        "tags": [ ... ],
        "categoryId": "...",
        "liveBroadcastContent": "...",
        "localized": {
         "title": "...",
         "description": "..."
        },
        "defaultAudioLanguage": "..."
       }
      }
     ]
    }
    

    The description can be found at items.localized.description.

提交回复
热议问题