代码之家  ›  专栏  ›  技术社区  ›  d_stack

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

  •  0
  • d_stack  · 技术社区  · 7 年前

    我正试图使用YouTube API在给定的国家找到一组特定的频道。

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

    它通过浏览器返回“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运行相同的查询时,不会返回国家值。

    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
                            )
    
                    )
    

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

    1 回复  |  直到 7 年前
        1
  •  0
  •   Tempus    7 年前

    这与你的代码无关。

    第二个通道没有在那里设置位置,因此它不会显示在结果中。