How to get a user's Google+ ID from a YouTube channel ID

一个人想着一个人 提交于 2019-12-07 19:13:51

问题


I'm running a service where people can connect their Google account using oauth 2.0, and with YouTube permissions I can manage their channels/access their YouTube Channel ID.

However, my question is whether or not you can go backwards. i.e. How can you determine the Google Account Owner from a given YouTube channel ID?


回答1:


googlePlusUserId is now deprecated from

https://developers.google.com/youtube/v3/docs/channels#properties

contentDetails.googlePlusUserId no longer exists as part of the contentDetails part.

Based on this excerpt from their change-log

June 13, 2016

This update contains the following changes:

  • The channel resource's contentDetails.googlePlusUserId property has been deprecated. Previously, the property was only present if the channel was associated with a Google+ profile. Following the deprecation, the property will no longer be included in any channel resources.
  • The comment resource's snippet.authorGoogleplusProfileUrl property has been deprecated. Previously, the property was only present if the channel was associated with a Google+ profile. Following the deprecation, the property will no longer be included in any comment resources.

Since neither of these properties will be returned following the deprecation, both properties have been removed from the corresponding resource documentation.




回答2:


You can get user Google+ ID through a YouTube API(v3) request, e.g.:

https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={CHANNEL_ID}&key={YOUR_API_KEY}

Will return:

{
   "kind": "youtube#channelListResponse",
   "etag": "fooHash",
   "pageInfo": {
      "totalResults": 1,
      "resultsPerPage": 1
   },
   "items": [{
         "kind": "youtube#channel",
         "etag": "fooHash",
         "id": "fooHash",
         "contentDetails": {
            "relatedPlaylists": {
               "likes": "fooHash",
               "favorites": "fooHash",
               "uploads": "fooHash"
             },
          }
          "googlePlusUserId": "{ID}"
   }]
}



回答3:


Probably people can not get Google+ ID from YouTube API(v3). But even the channel owner did not create google plus account, you can know it in advance on the channel HTML document by using XHR or curl.

  1. visit channel page.

    https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ

  2. Catch Javascript object from Developer tool on browser at the page.

    ytInitialData.metadata.channelMetadataRenderer.ownerUrls

    [ "http://www.youtube.com/user/googlechrome",
    "https://plus.google.com/100585555255542998765" ]

  3. Second one is always google plus address and the number is Google+ ID. You can get more info from ytInitialData at the channel page if necessary.

One example. https://www.youtube.com/channel/UCiQPrVjbUlZBWY0fVtvpoKg

About that channel id(UCiQPrVjbUlZBWY0fVtvpoKg) You can not get Google+ ID from YouTube API(v3), but you can get Google+ ID at the channel directly when you can access html document or read it. Even if the channel owner did not create google plus account, the Youtube already made Google+ ID together.



来源:https://stackoverflow.com/questions/35823274/how-to-get-a-users-google-id-from-a-youtube-channel-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!