Deconf.com

  • WordPress Plugins
  • Joomla Extensions

How can I get the CHANNEL ID or USER ID of an YouTube account?

Last Updated on August 26, 2014 by Alin Marcu

If you want to generate reports using the YouTube Analytics API you will need to have your YouTube USER_ID. Some reports from YouTube Data API will also require the CHANNEL_ID.

You can manually retrieve the USER ID and CHANNEL ID of your YouTube account by accessing this link:

YouTube Channel ID and User ID info

By clicking on the above link, a screen with your account’s Advanced Information will show up, something similar to this:

YouTube CHANNEL ID and USER ID

If you need to programmatically get the CHANNEL ID or USER ID of a YouTube account, you will have to enable YouTube Data API v3 on Services tab on your Google Console Project.

Requirements:

– well knowledge about Google APIs and how they work

– good PHP skills

– google-api-php-client library

– Google API Project with YouTube Data API service enabled

– a PHP application already authorized to access an YouTube account information

Assuming that you’ve already authorized your application, I will proceed to the PHP function that will help you retrieve the CHANNEL_ID from an YouTube account:

function yt_channelid ($client){
	$client->setUseObjects(true);
	require_once 'src/contrib/Google_YouTubeService.php';
	$service = new Google_YouTubeService($client);
	try{
	$data = $service->channels->listChannels('snippet', array('mine' => 'true',));
	} catch (Google_ServiceException $e) {
		echo "An error has occurred!";
		return;
	}

	$item=$data->items[0]->id;

	$client->setUseObjects(false);
}

The above function uses google-api-php-client library.

To obtain the channelid we will use the following statement:

$channelid=yt_channelid($client);

The USER_ID seems to be the CHANNEL_ID without the UC part. Because that UC is subject to feature changes and I didn’t knew how to retrieve it, I just stripped off the first two chars from CHANNEL_ID.

$userid=substr($channelid,2);

In conclusion, using the listChannels method fromĀ Google_YouTubeService class will allow you to get the USER ID and CHANNEL ID for a YouTube account.

You should also have a look atĀ YouTube Analytics Dashboard, a WordPress plugin and a full functional example of YouTube Data API and YouTube Analytics API usage.

Share this:

  • Twitter
  • Facebook

Follow deconf.com

Subscribe to receive free updates when new plugins, tutorials or posts are available

Categories

  • WordPress
  • Joomla
  • Reviews
  • Tutorials
  • Articles
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Donate or Contribute
  • Contact
  • Data Usage Policy for my Extensions
  • Privacy Policy

Copyright © 2021 · DeConf.com