YouTube API 3渠道按用户名和ID不一致

时间:2016-09-07 20:49:23

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

2 个答案:

答案 0 :(得分:0)

  

当我按ID搜索频道时..我没有返回任何项目。

试试channel.list的Try-it section。我可以使用以下参数获取JSON响应:

 part->contentDetails
 id-> yourchannel ID

Authorize and Execute

它返回的响应根本不是空的。

{
 "kind": "youtube#channelListResponse",
 "etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/FiuYcDu7WFmoFVcLDRvENYGl_tQ\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {

   "kind": "youtube#channel",
   "etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/QjMybH99xT3x-znrh2Yerx_0DWk\"",
   "id": "{my channel id}",
   "snippet": {
    "title": "{my channel name}",
    "description": "",
    "publishedAt": "2011-10-10T15:30:40.000Z",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    },
    "localized": {
     "title": "{my channel name}",
     "description": ""
    }
   }
  }
 ]
}

这对我来说有很多结果。

  

但是当我按userName搜索时,它会返回我刚才的频道ID   搜索。

在上面的channels.list试用文档中,forUsername定义为forUsername参数指定YouTube用户名,从而请求与该用户名相关联的频道。所以我认为它正在做它的工作。

关于forUsername参数的附加说明是,它用于将您的任意旧版YouTube用户名(即旧的Youtube帐户)转换为使用API​​的v3的频道ID。更多内容见Work with Channel IDs指南。

答案 1 :(得分:0)

  

当我通过userName搜索时,它返回我刚才的频道ID   搜索

您错过了forUsernamechannelID搜索的重要部分。这是代码段部分,而不是contentDetails

forUsername

 https://www.googleapis.com/youtube/v3/channels?&part=snippet,id&forUsername=RealMiBs&title&key={YOUR_API_KEY}

id频道:

https://www.googleapis.com/youtube/v3/channels?&part=snippet,id&id=UC_pwIXKXNm5KGhdEVzmY60A&title&key={YOUR_API_KEY}

这将完全恢复如下:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/VnicD0AYsCI7KlKKcdsmdIlWUMs\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/Nl4tuuOFwuPOdHmP_Ky3vuIQ2Gg\"",
   "id": "UC_pwIXKXNm5KGhdEVzmY60A",
   "snippet": {
    "title": "CJENMMUSIC Official", <== Channel Name
    "description": "Asia's No.1 Entertainment & Media Company", <== Channel Desctiption
    "customUrl": "cjenmmusic", <=== Channel URL who has been qualified - to and for - claimed it
    "publishedAt": "2011-03-25T04:48:40.000Z",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    },
    "localized": {
     "title": "CJENMMUSIC Official",
     "description": "Asia's No.1 Entertainment & Media Company"
    }
   }
  }
 ]
}

如果您只是指向contentDetails,它几​​乎不会返回任何内容:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/C7SnOhT2c-Fs2R9f6JlxlOPWc34\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/3RTKaEQC9GX8c58R2Bhd8G1y3zM\"",
   "id": "UC_pwIXKXNm5KGhdEVzmY60A",
   "contentDetails": { <============== detail contents
    "relatedPlaylists": {
     "uploads": "UU_pwIXKXNm5KGhdEVzmY60A",
     "watchHistory": "HL",
     "watchLater": "WL"
    }
   }
  }
 ]
}