【问题标题】:Google API: Find a Users YouTube ChannelGoogle API:查找用户 YouTube 频道
【发布时间】:2013-01-29 10:13:16
【问题描述】:

我正在使用 YouTube API 并试图获取用户的 YouTube 链接。唯一显示的是 Google+ 链接作为称为链接的字段。有没有办法从谷歌账户信息中获取用户的 Youtube 信息?

Google 响应在 json 响应中包含 first_name、given_name 和链接。

谢谢!

【问题讨论】:

  • 如果您可以提供有关您正在进行的 API 调用的详细信息、您收到的响应示例以及对内容的解释(包括示例),您的问题会更清楚您的意思是“用户的 YouTube 链接”。

标签: oauth youtube youtube-api


【解决方案1】:

根据 Google YouTube API channels list 文档,您可以获得 JSON 响应,其中包含与特定 Google 用户相关的所有 YouTube 频道。

第一步

显然,您需要确保使用 OAuth 2.0 登录 Google Developer API(确保您使用 YouTube 范围:https://www.googleapis.com/auth/youtube)。这是因为您需要一个access_token,才能加载用户特定的数据。

第二步

channels list API 可以通过以下方式查找频道:用户名、频道 ID 等...但是,不需要 ID 字符串。相反,您可以将 mine 布尔参数设置为 true,以获取特定 Google 用户拥有的 YouTube 频道(您不必指定 Google 用户的 ID,因为 access_token 允许 YouTube知道哪个用户正在尝试加载数据)。

要使用 API,请使用以下 URL 发出请求(将“YOUR_ACCESS_TOKEN_HERE”替换为您的access_token):

https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&mine=true&access_token=YOUR_ACCESS_TOKEN_HERE

这是您将收到的JSON 响应:

{
 "kind": "youtube#channelListResponse",
 "etag": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
   "id": "YOUTUBE_CHANNEL_ID",
   "snippet": {
    "title": "Daniel Sadjadian",
    "description": "I’m Daniel Sadjadian - Car enthusiast, computer programmer & entrepreneur running my own business. I live life to the max and try my best to get the most out of each day. Every moment counts :)",
    "customUrl": "danielsadjadian",
    "publishedAt": "2013-11-09T19:47:41.000Z",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-EF0LibpIsEY/AAAAAAAAAAI/AAAAAAAAAAA/n0mUHQnyfkc/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-EF0LibpIsEY/AAAAAAAAAAI/AAAAAAAAAAA/n0mUHQnyfkc/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-EF0LibpIsEY/AAAAAAAAAAI/AAAAAAAAAAA/n0mUHQnyfkc/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    },
    "localized": {
     "title": "Daniel Sadjadian",
     "description": "I’m Daniel Sadjadian - Car enthusiast, computer programmer & entrepreneur running my own business. I live life to the max and try my best to get the most out of each day. Every moment counts :)"
    },
    "country": "GB"
   },
   "contentDetails": {
    "relatedPlaylists": {
     "likes": "LLXQYiggNxzVJ51ofKyG2ZUg",
     "favorites": "FLXQYiggNxzVJ51ofKyG2ZUg",
     "uploads": "UUXQYiggNxzVJ51ofKyG2ZUg",
     "watchHistory": "HL",
     "watchLater": "WL"
    }
   },
   "statistics": {
    "viewCount": "30305",
    "commentCount": "0",
    "subscriberCount": "100",
    "hiddenSubscriberCount": false,
    "videoCount": "25"
   }
  }
 ]
}

JSON 响应包含有关用户频道的详细信息,包括频道 ID。然后,您可以使用频道 ID(与其他 YouTube API 一起)加载频道视频/播放列表/活动/等...

【讨论】:

  • 您好,我知道这条评论是很久以前发布的,但是您知道是否仍然可以根据他的 google-sign-in 信息找到某人的 youtube 频道?
【解决方案2】:

我不知道这是否正是您想要的,但使用 Google+ API 您可以获得用户网址,其中之一可以是用户 YouTube 频道网址

更多信息: https://developers.google.com/+/api/latest/people/get

例子:

请求:

https://www.googleapis.com/plus/v1/people/117629885563933382879?key={YOUR_API_KEY}

回复:

{
 "kind": "plus#person",
 "etag": "\"l9gWq2lTiBDNZWBx8kpM7h7VNYs/as5084EFycaxtFP9IxDLvhbwZKM\"",
 "birthday": "0000-12-30",
 "gender": "male",
 "urls": [
  {
   "value": "http://twitter.com/matiasmolinas",
   "type": "other"
  },
  {
   "value": "http://gplus.to/matiasmolinas",
   "type": "other"
  },
  {
   "value": "http://ar.linkedin.com/in/matiasmolinas",
   "type": "other"
  },
  {
   "value": "https://www.facebook.com/matias.molinas",
   "type": "other"
  },
  {
   "value": "http://www.youtube.com/user/matiasmolinasvideo",
   "type": "other"
  },
  {
   "value": "http://stackoverflow.com/users/1427200/matias-molinas",
   "type": "other"
  },
  {
   "value": "http://santafegtug.blogspot.com/",
   "type": "other"
  },
  {
   "value": "http://fuse21.blogspot.com/",
   "type": "other"
  },
  {
   "value": "http://lookthiscode.blogspot.com.ar/",
   "type": "other"
  },
  {
   "value": "https://yt-topic-explorer.googlecode.com/git/dist/index.html",
   "type": "other"
  },
  {
   "value": "http://santafegtug.appspot.com/",
   "type": "other"
  }
 ],
 "objectType": "person",
 "id": "117629885563933382879",
 "displayName": "Matias Molinas",
 "name": {
  "familyName": "Molinas",
  "givenName": "Matias"
 },
 "aboutMe": "Citas favoritas:<br /><br />Dentro de veinte años te sentirás más desilusionado por las cosas que no hiciste que por aquéllas que hiciste. Así que suelta las amarras. Navega fuera de la bahía segura. Atrapa los alisios en tus velas. Explora. Sueña. Descubre.<br />",
 "url": "https://plus.google.com/117629885563933382879",
 "image": {
  "url": "https://lh3.googleusercontent.com/-AJKFDGod6us/AAAAAAAAAAI/AAAAAAAAD64/Olccnle-qH4/photo.jpg?sz=50"
 },
 "organizations": [
  {
   "name": "UNER",
   "title": "Bioingenieria",
   "type": "school",
   "primary": false
  },
  {
   "name": "Software Consultant",
   "title": "Software Consultant",
   "type": "work",
   "startDate": "2011",
   "endDate": "2011",
   "primary": true
  },
  {
   "name": "Software Santa Fe",
   "type": "work",
   "endDate": "2011",
   "primary": false
  }
 ],
 "placesLived": [
  {
   "value": "Santa Fe, Argentina",
   "primary": true
  }
 ],
 "isPlusUser": true,
 "verified": false,
 "cover": {
  "layout": "banner",
  "coverPhoto": {
   "url": "https://lh3.googleusercontent.com/-DjGbmNDlV3U/UNCgpGJu_WI/AAAAAAAAD7Q/7Uk2WidwxnI/w940-h428/gdesummit.png",
   "height": 428,
   "width": 940
  },
  "coverInfo": {
   "topImageOffset": -83,
   "leftImageOffset": 0
  }
 }
}

【讨论】:

  • 这似乎正是我想要的。立即查看。
  • 这非常方便:developers.google.com/oauthplayground 我还没有找到任何一种工作方式,但我想我现在已经很接近了,因为我有完整的 api 端点列表 :)
  • 希望你们看到这条评论。如果 YouTube 频道位于链接的 Others 标签下,上述请求只会返回该频道。如果它在 YouTube 标签中,则不会出现在结果中。因此,它仅适用于数千个帐户中的少数几个频道。是否有另一种方法可以返回与给定 G+ ID 关联的每个频道?
  • 一个令人钦佩的答案,但它不可靠且不提供 YouTube 频道 ID。我的回答使用 YouTube API,可靠地加载与 Google Authenticated 用户相关的所有频道。
猜你喜欢
  • 2021-08-03
  • 1970-01-01
  • 2013-06-15
  • 2014-08-17
  • 2013-09-03
  • 1970-01-01
  • 2017-04-22
  • 1970-01-01
相关资源
最近更新 更多