谷歌API:查找用户YouTube频道



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

Google响应在json响应中有first_name、given_name和link。

谢谢!

根据Google YouTube API频道列表文档,您可以获得包含特定Google用户的所有YouTube频道的JSON响应。

第一步

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

第二步

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

为了使用API,请使用以下URL发出请求(将"YOUR_ACCESS_TOKEN_HERE"替换为access_token):

https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&mine=真&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+API,你可以获得用户url,其中一个可以是用户YouTube频道url

更多信息:https://developers.google.com/+/api/最新/人员/获取

示例:

请求:

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

最新更新