感谢您的帮助,我正在尝试使用Api V3从YouTube上的特定 channel 获取横幅图像。

我正在使用以下格式:



获取以下信息:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/s93ZotjagYf2fFr0mqM9MxU-SaU\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"F9iA7pnxqNgrkOutjQAa9F2k8HY/Tz1L-MnftzBIXiDdwzUINRNgkUY\"",
   "id": "UCD6YMmVyF50oiwXisgbF-2w",
   "brandingSettings": {
    "channel": {
     "title": "ArrolladoraLimonVEVO",
     "keywords": "Arrolladora Limon VEVO Music",
     "showRelatedChannels": true,
     "showBrowseView": true,
     "featuredChannelsTitle": "Featured Channels",
     "featuredChannelsUrls": [
      "UC2pmfLm7iq6Ov1UwYrWYkZA",
      "UCnrJTmHzaiAjuA_pTpfd9Uw"
     ],
     "unsubscribedTrailer": "5ZZ6I4pmGIE",
     "profileColor": "#000000"
    },
    "image": {
     "bannerImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w1060-fcrop64=1,00005a57ffffa5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerMobileImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w640-fcrop64=1,32b75a57cd48a5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerTabletLowImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w1138-fcrop64=1,00005a57ffffa5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerTabletImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w1707-fcrop64=1,00005a57ffffa5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerTabletHdImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w2276-fcrop64=1,00005a57ffffa5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerTabletExtraHdImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w2560-fcrop64=1,00005a57ffffa5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerMobileLowImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w320-fcrop64=1,32b75a57cd48a5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerMobileMediumHdImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w960-fcrop64=1,32b75a57cd48a5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerMobileHdImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w1280-fcrop64=1,32b75a57cd48a5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerMobileExtraHdImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w1440-fcrop64=1,32b75a57cd48a5a8-nd/la_arrolladora_youtube_pre_order.png",
     "bannerTvImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w2120-fcrop64=1,00000000ffffffff-nd/la_arrolladora_youtube_pre_order.png",
     "bannerTvLowImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w854-fcrop64=1,00000000ffffffff-nd/la_arrolladora_youtube_pre_order.png",
     "bannerTvMediumImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w1280-fcrop64=1,00000000ffffffff-nd/la_arrolladora_youtube_pre_order.png",
     "bannerTvHighImageUrl": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w1920-fcrop64=1,00000000ffffffff-nd/la_arrolladora_youtube_pre_order.png"
    },
    "hints": [
     {
      "property": "channel.banner.mobile.medium.image.url",
      "value": "https://yt3.ggpht.com/-Cv2TDQuv-kw/VJC0D9dimxI/AAAAAAAAADU/vaNVkDmXyz4/w640-fcrop64=1,32b75a57cd48a5a8-nd/la_arrolladora_youtube_pre_order.png"
     },
     {
      "property": "channel.featured_tab.template.string",
      "value": "Everything"
     },
     {
      "property": "channel.modules.show_comments.bool",
      "value": "True"
     },
     {
      "property": "channel.banner.image_height.int",
      "value": "0"
     }
    ]
   }
  }
 ]
}

问题出在我的PHP代码上,我收到以下错误:



码:
<?php
 $feedURL2 = "https://www.googleapis.com/youtube/v3/channels?part=brandingSettings&id=UCD6YMmVyF50oiwXisgbF-2w&key=*****";

function GetytBanner() {
    global $feedURL2;
    $json = file_get_contents ($feedURL2);
    $obj = json_decode($json,true);
    return $obj['items']['image']['bannerImageUrl'];
}

 ?>

<?php echo GetytBanner(); ?>

最佳答案

我使用了错误的格式:

return $obj['items']['image']['bannerImageUrl'];

正确方法:
return $obj['items'][0]['brandingSettings']['image']['bannerTvHighImageUrl'];

10-06 08:13