Home Articles

使用Youtube Api的错误和故障

Asked
Viewed 1477 times
0

所以我在我的网站上使用youtube的APi,我上传的视频和保存到特定网站的视频都会被发布 . 问题是,我上传显示我发布的视频的页面,第一个显示带有我的 Channels 名称的“视频”,它不是真正的视频,但它有一个id和所有这些 . 但它在我的YouTube Channels 上是不可见的,我没有在我的 Channels 上传这种类型的视频 . 在底部是PHP代码Api代码:

我还获得了在网站上显示的每个视频的缩略图,但有些视频没有显示缩略图 .

现在到最后一件事我在APi的控制台中得到了这些错误

  • Failed to load resource: the server responded with a status of 404 ()

  • `解析头X-XSS-Protection时出错:1;模式=块; report = https://www.google.com/appser

ve / security-bugs / log / youtube:字符位置22处安全页面的不安全报告URL . 将应用默认保护 .

<?php

function get_videos()
{
  $json_link="https://www.googleapis.com/youtube/v3/search?key=Api-key&channelId=Channel_id&part=snippet,id&order=date&maxResults=10";

  $json = file_get_contents($json_link);
  $obj = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

  if( isset($obj['items']) )
  {
    foreach($obj['items'] as $post)
    {
      $id = isset($post['id']['videoId']) ? $post['id']['videoId'] : "";
      $published_at = isset($post['snippet']['publishedAt']) ? $post['snippet']['publishedAt'] : "";
      $title = isset($post['snippet']['title']) ? $post['snippet']['title'] : "";
      $description = isset($post['snippet']['description']) ? $post['snippet']['description'] : "";
      $thumbnail = "https://i.ytimg.com/vi/{$id}/maxresdefault.jpg";


        ?>
        <div class="row grid-list-wrapper no-gutter-space" id="shots">
    <div class="col-sm-4 portfolio-item container2">
      <div>
        <div class="middle2">
            <p class="text2"><strong><?php echo $title;?></strong></p>
         </div>
       </div>
       <img data-toggle="modal"
            data-target="<?php echo "#modal_$id";?>"
            src="<?php echo "$thumbnail";?>"
            class="image2" style="height:220px;width:390px;" />
          </div>

    <center>
        <div class="modal" id="<?php echo "modal_$id";?>" tabindex="-1" role="dialog">

          <h2 style="color:white;"><?php echo $title;?>
           <button type="button" class="close" data-dismiss="modal" aria-label="Close">
             <span aria-hidden="true">&times;</span>
            </button>
          </h2>
          <div class="modal-dialog" role="document">
                <?php
              echo
                "<iframe width=\"720\" height=\"410\""
                ." src=\"https://www.youtube.com/embed/$id\" frameborder=\"0\""
                ." allowfullscreen></iframe>";
                ?>
          </div>

  </div>
    </center>
       <?php
    }
  } else {echo "Videos could not be found or something went wrong :(";}
}
?>

这是api脚本的JSON文件:

{
 "kind": "youtube#searchListResponse",
 "etag": "\"_gJQceDMxJ8gP-8T2HLXUoURK8c/xToA0H6y7a6RTmJrkSY6DXE6gs8\"",
 "regionCode": "US",
 "pageInfo": {
  "totalResults": 5,
  "resultsPerPage": 50
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"_gJQceDMxJ8gP-8T2HLXUoURK8c/ndFVPddFgdf4xczeyIcPBlONiRo\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "pKFoAuyIHuE"
   },
   "snippet": {
    "publishedAt": "2018-02-24T22:14:30.000Z",
    "channelId": "UCdLRwYrtYj1ZsNKu0lxk9aA",
    "title": "Hihi",
    "description": "Website: https://swedcraft.net/",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/pKFoAuyIHuE/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/pKFoAuyIHuE/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/pKFoAuyIHuE/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Linus Janns",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"_gJQceDMxJ8gP-8T2HLXUoURK8c/J_uNqMQXteA_1q6gSm2oN54DADE\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "_ja8k6MHjE0"
   },
   "snippet": {
    "publishedAt": "2018-02-12T15:47:37.000Z",
    "channelId": "UCdLRwYrtYj1ZsNKu0lxk9aA",
    "title": "Some vines",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/_ja8k6MHjE0/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/_ja8k6MHjE0/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/_ja8k6MHjE0/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Linus Janns",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"_gJQceDMxJ8gP-8T2HLXUoURK8c/yPTJujmfy2l1U5kTi9lZlHaCFRo\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "7AxKOlZ-Qe8"
   },
   "snippet": {
    "publishedAt": "2018-02-11T05:21:04.000Z",
    "channelId": "UCdLRwYrtYj1ZsNKu0lxk9aA",
    "title": "Toilet prank gone wrong",
    "description": "website: https://www.swedcraft.net *–OBSERVE: These videos I post on this channel is for my website, if you (the owner) don't want them on the web or youtube please contact me insted of striking...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/7AxKOlZ-Qe8/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/7AxKOlZ-Qe8/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/7AxKOlZ-Qe8/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Linus Janns",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"_gJQceDMxJ8gP-8T2HLXUoURK8c/Es-CoB_YMSvsz47s_9TcID7n2_c\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "SwiEwLhIQIY"
   },
   "snippet": {
    "publishedAt": "2018-02-11T05:09:43.000Z",
    "channelId": "UCdLRwYrtYj1ZsNKu0lxk9aA",
    "title": "Doggie love",
    "description": "website: https://www.swedcraft.net *–OBSERVE: These videos I post on this channel is for my website, if you (the owner) don't want them on the web or youtube please contact me insted of striking...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/SwiEwLhIQIY/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/SwiEwLhIQIY/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/SwiEwLhIQIY/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Linus Janns",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"_gJQceDMxJ8gP-8T2HLXUoURK8c/tZpA7tgs5ehyQDs7U6hSefhbKuM\"",
   "id": {
    "kind": "youtube#channel",
    "channelId": "UCdLRwYrtYj1ZsNKu0lxk9aA"
   },
   "snippet": {
    "publishedAt": "2018-02-10T05:57:10.000Z",
    "channelId": "UCdLRwYrtYj1ZsNKu0lxk9aA",
    "title": "Linus Janns",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-XHBR63N3tYE/AAAAAAAAAAI/AAAAAAAAAAA/7oSIIyAvQO0/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-XHBR63N3tYE/AAAAAAAAAAI/AAAAAAAAAAA/7oSIIyAvQO0/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-XHBR63N3tYE/AAAAAAAAAAI/AAAAAAAAAAA/7oSIIyAvQO0/s800-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    },
    "channelTitle": "Linus Janns",
    "liveBroadcastContent": "none"
   }
  }
 ]
}

2 Answers

  • 0

    这是当前谷歌Chrome和Chromium中的一个已知错误:https://bugs.chromium.org/p/chromium/issues/detail?id=807304

    在其浏览器的当前版本中,出于某些安全原因,Chrome开发人员已将X-XSS-Protection的报告字段网址限制为同一域名 . 因此,当您使用某些嵌入代码嵌入视频时,在其中设置了标头报告= https://www.google.com/的另一台服务器下载,并且当您的网页未在google.com域托管时 - 会出现错误消息 .

  • 0

    我做的是我补充说:

    $url= isset($post['snippet']['thumbnails']['default']['url']) ? $post['snippet']['thumbnails']['default']['url'] : "";
    

    获取视频网址的代码,然后我添加了

    if( 0 == strcmp($url, "THE_URL_OF_THE_VIDEO") )
        {
        continue;
        }
    

    这将从网站上删除整个视频 . 目前还不清楚为什么它首先出现,因为我根本找不到任何关于它的信息,但我现在已经修复了它 .

Related