Search code examples
javaandroidyoutubeyoutube-apiandroid-youtube-api

Get User Name and Channel ID from YouTube API


I'm using Android to access both the YouTube Analytics API and the YouTube Data API. Currently I have the app working that if I hard code in my personal Channel ID the app can retrieve information about my personal YouTube account.

However, I am using the Android AccountPicker to use GoogleAuthUtil so I have access to the user's email address. Is there a way to query YouTube to return their Channel ID using their email address?

Also is there a way to query YouTube to just receive back the user's User Name? I would like to greet them when in my app.

Thanks in advance!
~Jskuzma


Solution

  • You can call channels->list with "part=id & mine=true"

    GET https://www.googleapis.com/youtube/v3/channels?part=id&mine=true&key={YOUR_API_KEY}

    Id is the channel's ID.

    You can get the video's title from the response under [snippet.title]. You can get the channel's title from the response under snippet.channelTitle.

    This title is what you are looking for to greet, but if you want to go deeper you can check if that account is linked with Google+ and use googleplususerid to retrieve more information via Google+ API.