从客户端与服务器(php)调用时,Youtube Data API返回不同的结果

时间:2017-07-21 21:30:58

标签: php youtube-api youtube-data-api

我正在尝试使用YouTube API查找特定国家/地区的一组特定频道。

当我运行此API调用时:

https://www.googleapis.com/youtube/v3/channels?id=UC63W4y26EXa7Vleh5Z-5fqw&key=*********************&part=statistics,snippet

通过浏览器返回“国家/地区”值作为“代码段”部分的一部分,如下所示。

{
 "kind": "youtube#channelListResponse",
 "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/wMuzbevD-QOXuqc28mDTsIwApQg\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/9zM43j9wzRZqCnqmk3ULgh-K_JM\"",
   "id": "UC63W4y26EXa7Vleh5Z-5fqw",
   "snippet": {
    "title": "Royalce",
    "description": "Hi all! I hope you enjoy the music (mixes) I put on this channel as much as I do! PM me for requests, Subs are always welcome :) !!",
    "customUrl": "bestofchannel",
    "publishedAt": "2014-05-01T15:53:46.000Z",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-DhTNWzQjfuo/AAAAAAAAAAI/AAAAAAAAAAA/KirAFaZlcsc/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-DhTNWzQjfuo/AAAAAAAAAAI/AAAAAAAAAAA/KirAFaZlcsc/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-DhTNWzQjfuo/AAAAAAAAAAI/AAAAAAAAAAA/KirAFaZlcsc/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    },
    "localized": {
     "title": "Royalce",
     "description": "Hi all! I hope you enjoy the music (mixes) I put on this channel as much as I do! PM me for requests, Subs are always welcome :) !!"
    },
    "country": "NL"
   },
   "statistics": {
    "viewCount": "2115236",
    "commentCount": "0",
    "subscriberCount": "4645",
    "hiddenSubscriberCount": false,
    "videoCount": "22"
   }
  }
 ]
}

但是,当我使用以下代码通过PHP运行相同的查询时,不会返回国家/地区值。

PHP代码:

try{
$searchResponse = $youtube->search->listSearch('id, snippet', array(
    'type' => 'channel',
    'maxResults' => 20,
    'topicId' => "/m/032tl",
    'regionCode' => 'DE',
));
}

结果:

          [1] => Array
                (
                    [kind] => youtube#searchResult
                    [etag] => "m2yskBQFythfE4irbTIeOgYYfBU/AjgQ_S7-ek2_Hma9-TmMGxRrnU4"
                    [id] => Array
                        (
                            [kind] => youtube#channel
                            [channelId] => UCK-4JyAcQYBasFAe367on7w
                        )

                    [snippet] => Array
                        (
                            [publishedAt] => 2009-05-29T00:14:11.000Z
                            [channelId] => UCK-4JyAcQYBasFAe367on7w
                            [title] => RachhLoves
                            [description] => I have a slight obsession with makeup, coffee & cookies. And by slight, I mean massive. This channel is dedicated to testing new makeup, sharing my beauty ...
                            [thumbnails] => Array
                                (
                                    [default] => Array
                                        (
                                            [url] => https://yt3.ggpht.com/-zN9sV9wWCls/AAAAAAAAAAI/AAAAAAAAAAA/dxZoEO6k1Tg/s88-c-k-no-mo-rj-c0xffffff/photo.jpg
                                        )

                                    [medium] => Array
                                        (
                                            [url] => https://yt3.ggpht.com/-zN9sV9wWCls/AAAAAAAAAAI/AAAAAAAAAAA/dxZoEO6k1Tg/s240-c-k-no-mo-rj-c0xffffff/photo.jpg
                                        )

                                    [high] => Array
                                        (
                                            [url] => https://yt3.ggpht.com/-zN9sV9wWCls/AAAAAAAAAAI/AAAAAAAAAAA/dxZoEO6k1Tg/s240-c-k-no-mo-rj-c0xffffff/photo.jpg
                                        )

                                )

                            [channelTitle] => RachhLoves
                            [liveBroadcastContent] => none
                        )

                )

有没有人知道为什么“snippet”部分在通过浏览器或服务器/ php运行查询时会为同一资源(youtube“频道”)返回不同的结果?

1 个答案:

答案 0 :(得分:0)

它与您的代码无关 您的示例显示了对两个不同频道的呼叫 第二个频道没有设置位置,因此它不会显示在结果中。

因为它不是强制性的,不幸的是并不是每个人都会设置它。