Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google API: Find a Users YouTube Channel

I was using the YouTube API and was trying to get a user's YouTube Link. The only thing that shows up is the Google+ link as a field called link. Is there anyway to get the users's Youtube information from the Google Account info?

The Google Response has first_name,given_name, and link in the json response.

Thanks!

like image 294
Justin Thomas Avatar asked Feb 13 '13 18:02

Justin Thomas


2 Answers

As per the Google YouTube API channels list documentation, you can get a JSON response containing all the YouTube channels that pertain to a specific Google user.

Step One

Obviously you need to ensure that you use OAuth 2.0 to login to the Google Developer API (ensuring that you use to YouTube scope: https://www.googleapis.com/auth/youtube). This is because you need an access_token, in order to load user specific data.

Step Two

The channels list API can find channels via: username, channel ID, etc... An ID string is not required however. Instead you can set the mine boolean parameter to true, in order to get the YouTube channels owned by a particular Google user (you don't have to specify the ID of the Google user, because the access_token lets YouTube know which user is attempting to load the data).

In order to use the API, make a request using the following URL (replacing 'YOUR_ACCESS_TOKEN_HERE' your access_token):

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

Here is the JSON response that you'll get:

{
 "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"
   }
  }
 ]
}

The JSON response includes details about the user's channel including the channel ID. You can then use the channel ID (in conjunction with other YouTube APIs) to load the channel videos/playlists/activities/etc...

like image 95
Supertecnoboff Avatar answered Sep 21 '22 13:09

Supertecnoboff


I do not know if it's exactly what you want, but using the Google+ API you can get the user urls and one of them can be the user YouTube channel url

More info: https://developers.google.com/+/api/latest/people/get

Example:

Request:

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

Response:

{
 "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
  }
 }
}
like image 20
Matias Molinas Avatar answered Sep 22 '22 13:09

Matias Molinas