Youtube Data API 返回无效数据 [英] Youtube Data API is returning invalid data

查看:35
本文介绍了Youtube Data API 返回无效数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定如何提问,但我有一个 php 脚本,可以从 youtube-v3-api 为我的 youtube 频道提取数据,主要是我已发布的视频列表.它一直运行良好,直到今天早些时候我再次运行它,因为我添加了一个新视频.这是 items 数组中第一个对象的输出

I'm not really sure how to ask this, but I have a php script that pulls data from the youtube-v3-api for my youtube channel, mainly a list of videos that I have published. It's been working great up until earlier today when I went to run it again because I added a new video. Here's the output for the first object in the items array

items:[  
   {  
      kind:"youtube#searchResult",
      etag:""      XpPGQXPnxQJhLgs6enD_n8JR4Qk/tluoWYe5GE9lVFAkcMtcec2Ycug"",
      id:{  
         kind:"youtube#channel",
         channelId:"UCD8d3FGC907iS1qiMF0ccxA"
      },
      snippet:{  
         publishedAt:"2006-04-30T19:39:08.000Z",
         channelId:"UCD8d3FGC907iS1qiMF0ccxA",
         title:"Travis Ballard",
         description:"",
         thumbnails:{  
            default:{  
               url:"https://yt3.ggpht.com/-L5MV7tUNjlk/AAAAAAAAAAI/AAAAAAAAAAA/dXNuqxAYprw/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
            },
            medium:{  
               url:"https://yt3.ggpht.com/-L5MV7tUNjlk/AAAAAAAAAAI/AAAAAAAAAAA/dXNuqxAYprw/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
            },
            high:{  
               url:"https://yt3.ggpht.com/-L5MV7tUNjlk/AAAAAAAAAAI/AAAAAAAAAAA/dXNuqxAYprw/s800-c-k-no-mo-rj-c0xffffff/photo.jpg"
            }
         },
         channelTitle:"Travis Ballard",
         liveBroadcastContent:"none"
      }
   }
]

这不代表我频道上的视频?而且,它根本就没有顺序.它应该按日期排序,因为我在我的 php 脚本中要求它:

This does not represent a video on my channel? also, it's not in order at all. It should be ordered by date as i'm asking it to in my php script:

    <?php

  const APIKEY = 'MyAPIKeyHere';
  const CHANNELID = 'UCD8d3FGC907iS1qiMF0ccxA';
  const VIDEO_COUNT = 50;

  class FetchYoutubeVideos {

    private $api_key = null;
    private $channel_id = null;
    private $count = null;

    public function __construct($api_key, $channel_id, $count = 10) {
      $this->api_key = $api_key;
      $this->channel_id = $channel_id;
      $this->count = $count;

      $this->writeToFile(
        'videos.json',
        $this->fetch($this->getApiUrl())
      );
      printf( 'fetched videos from: %s', $this->getApiUrl());
    }

    public function getApiUrl($options = array()) {
      $endpoint = 'https://www.googleapis.com/youtube/v3/search';
      $default_options = array(
        'key' => $this->api_key,
        'channelId' => $this->channel_id,
        'part' => 'snippet,id',
        'order' => 'date',
        'maxResults' => $this->count
      );

      $options = array_merge($options, $default_options);
      return sprintf('%s/?%s', $endpoint, http_build_query($options));
    }

    public function fetch($url) {
      $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

      $result = curl_exec($ch);
      return $result;
    }

    public function writeToFile($filename, $data) {;
      $fh = fopen($filename, 'w+');
      fwrite($fh, $data, strlen($data));
      fclose($fh);
    }
  }

  $fetchVideos = new FetchYoutubeVideos(APIKEY, CHANNELID, VIDEO_COUNT);

最新的视频应该是Tragic - Rock-a-Hoola Revisited",然后是Rocket Timelapse - Anycubic i3 Mega".您可以参考我的 yt 频道,看看它应该返回什么:https://www.youtube.com/channel/UCD8d3FGC907iS1qiMF0ccxA?view_as=subscriber

The newest video should be 'Tragic - Rock-a-Hoola Revisited' and then 'Rocket Timelapse - Anycubic i3 Mega'. You can reference my yt channel to see what it should be returning: https://www.youtube.com/channel/UCD8d3FGC907iS1qiMF0ccxA?view_as=subscriber

对它改变的原因有什么见解吗?或者为什么它没有返回它应该返回的数据?

Any insights into why it changed? Or why it's not returning the data that it should be?

推荐答案

您遇到了一个已知几天的 API 问题.跟进 https://issuetracker.google.com/issues/128673552,或答案已在本网站上提供(例如 https://stackoverflow.com/a/55246970/8327971).

You experienced an API issue which is known for a few days now. Follow-up https://issuetracker.google.com/issues/128673552, or the answers already given on this site (e.g. https://stackoverflow.com/a/55246970/8327971).

我们将通过这两个链接引导您找到解决手头问题的方法.

Either of the two links we'll lead you to find a workaround for the issue at hand.

请注意,到目前为止,Google 一直没有提供 ETA 来确定何时重新启用它禁用的 API 功能.我想可能还需要几天(也许几周?),直到我们看到那些禁用的功能再次运行.

Note that, until now, Google has refrained itself from providing an ETA for when it'll enable back the API's features it disabled. I suppose that it may well take a few more days (perhaps weeks?) until we'll see those disabled features working again.

这篇关于Youtube Data API 返回无效数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆