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

Youtube Data API returning different results when calling from the client vs. the server (php)

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

当我 运行 这个 API 调用时:

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

通过浏览器 returns "country" 值作为 "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" 部分 returns 相同资源 (youtube "channel") 在 运行 通过浏览器或通过server/php?

与你的代码无关
您的示例显示了对两个不同频道的调用。
第二个通道没有设置位置,所以不会显示在结果中。

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