如果用户视频从 youtube 中删除,我该如何将精选视频更改为我网站上最新上传的视频?

If user video removed from youtube , how do I change featured video to newest uploaded video on my website?

$url    =   "https://www.googleapis.com/youtube/v3/videos?id=".$row['video_id']."&part=contentDetails&key=[here is my Developer key]";

    if(file_get_contents($url))
    {
     return true;
    }
     else
     {
     false;
     }

当我检查视频 ID 时,如果视频存在,它会显示如下结果:

{
 "kind": "youtube#videoListResponse",
 "etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/pw80UEKFm5y728vQU5kjhUJTHGg\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#video",
   "etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/fBBgINoeGCSLK9f4shEUiy1MfeY\"",
   "id": "tyV0npY-0g8",
   "contentDetails": {
    "duration": "PT17M36S",
    "dimension": "2d",
    "definition": "hd",
    "caption": "false",
    "licensedContent": true
   }
  }
 ]
}

如果视频不存在 id 它会显示总结果 0,如下所示:

enter code here
{
 "kind": "youtube#videoListResponse",
 "etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/Rk41fm-2TD0VG1yv0-bkUvcBi9s\"",
 "pageInfo": {
  "totalResults": 0,
  "resultsPerPage": 0
 },
 "items": []
}

我正在将 videoid 存储在数据库中。现在,如果该视频在 youtube 上不存在,它会向用户生成一条通知:"your feature video is removed kindly update your video to newest upload video......."

这里也是屏幕截图:

请帮帮我。

您的屏幕截图显示的视频确实存在,但不允许嵌入到 YouTube 之外。检查一下:

将 'status' 添加到您的零件参数:

$url    =   "https://www.googleapis.com/youtube/v3/videos?id=".$row['video_id']."&part=contentDetails,status&key=[here is my Developer key]";

然后您可以检查结果中的 'embeddable' 字段:

"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true

}