Is there a field for knowing if the youtube channel is verified from the Youtube API?
Asked Answered
S

5

21

I am using the Youtube data API and I needed to know if there is any way of finding that the youtube channel is a Verified one.

Silsby answered 10/12, 2013 at 2:17 Comment(0)
A
2

RE: mpgn's solution, note that there's a distinction between whether the G+ account is Verified and whether one or more of the accounts YouTube channels are Verified. It's possible for an account to have more than one channel, and each of those channels are verified independently, and for channels to be unverified even though the associated G+ account is verified.

As @Paul Blakely suggests, the current best way to do this is to check the status.longUploadStatus flag, per https://developers.google.com/youtube/v3/docs/channels

Arabic answered 12/10, 2016 at 17:43 Comment(2)
The "verified" badge is not the "verified" of youtube.com/verify so if looking for the badge status.longUploadStatus is not a good meter.Bite
NOTE!! You must request the status part when making the listChannels call, otherwise you won't be able to access the longUploadStatus field.Integrand
L
2

As of November, 2022, the YouTube Data API provides no method for determining whether or not a given YouTube channel is or is not verified. Instead, the current approach that yields reliable results is to scrape the channel, and parse a bit of JSON, and search the resulting structure.

We'll start by loading the server response for a given channel. Below I have a channel ID hard-coded in as the id variable:

const id = 'UCFNTTISby1c_H-rm5Ww5rZg';
const response = await needle( 'get', `https://www.youtube.com/channel/${id}` );

With our response object, we should now proceed to check that a 200 OK was received, indicating there were no issues retrieving the page data, and that it is safe to proceed:

if ( response.statusCode === 200 ) {
    // proceed to search for verification status
}

Within the block following the condition is where we can start to retrieve the initial data for the YouTube page. When serving a channel page, YouTube will also serve initial data for the channel itself, presumably to speed up delivery among other reasons.

We'll look for this initial data, parse it as JSON, and sift through the results:

const json = response.body.match( /ytInitialData = (.*?);<\/script>/ )[1];
const parsed = JSON.parse( json );

With our data parsed, we'll turn our attention now to one piece of the resulting structure, the c4TabbedHeaderRenderer property. This is where badges for the page (such as a verification badge) are stored. We'll also define a verifiedLabel, to explain what it is we're seeking:

const header = parsed.header.c4TabbedHeaderRenderer;
const verifiedLabel = 'BADGE_STYLE_TYPE_VERIFIED';

Lastly we need to confirm that badges is an array (it may not be, in the event the channel has no badges to enumerate), and follow that up with a check for our verifiedLabel badge:

const verified = Array.isArray(header.badges) && header.badges.some( badge => {
    return badge.metadataBadgeRenderer.style === verifiedLabel
});

At this point, verified is either true (if the channel is verified), or false. I hope this helps!

Lubbock answered 10/11, 2022 at 22:32 Comment(0)
S
1

just ran into this today, and while the channelBranding of the V3 youtube API looks promising, I couldn't get it to return if the account/channel user id was verified or not

so I threw up a pretty lame php script that uses DOM model searching to examine the html directly. to return true if the following element is present.

<a href="//support.google.com/youtube/bin/answer.py?answer=3046484&amp;hl=en" class="qualified-channel-title-badge" target="_blank">

As of today (9/8/2014) a verified user will return true..

<?php
function isVerified($youtubeUser) 
{ 
    $youtubeUser = trim($youtubeUser); 
    $url = '\''."https://www.youtube.com/user/".$youtubeUser.'\'';
    $url = "https://www.youtube.com/user/".$youtubeUser ;
    $Verified = false;
    echo "<BR>looking at $url "; 

    $ch = curl_init();
    $timeout = 10;
    curl_setopt($ch, CURLOPT_URL, "$url");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $html = curl_exec($ch);
    curl_close($ch);

    $dom = new DOMDocument;
    @$dom->loadHTML($html);

    foreach ( $dom->getElementsByTagName('a') as $link ) {
        $myVar = $link->getAttribute('class');
        $search = "qualified-channel-title-badge";
        $found=false;
        $found = strpos($myVar, $search); 
        if ( $found  !== false) { 
            $Verified = true;  //echo "<BR><font color=green>TRUE</font>";
        } else {
            $Verified = false; //echo "<BR><font color=red>FALSE</font>";
        }
    } 

    if ( $Verified ) {
    return true;
    } else {
    return false;
    }
}
?>

Bye for now!

Sarcomatosis answered 8/9, 2014 at 18:52 Comment(0)
G
0

On verified channels, the class "has-badge" is present.

Work in 2018:

<?php
$key = 'has-badge';
$channel = file_get_contents('https://www.youtube.com/...');

if( stripos($channel, $key) !== FALSE )
    echo "Verified";
else
    echo "Not Verified";
?>
Gowk answered 5/1, 2018 at 14:57 Comment(0)
S
-1

If may be possible to check infer the verified status of a youtube channel via the status.longUploadsStatus flag being either allowed or eligible, as currently this feature requires the associated youtube account to be verified.

source : https://developers.google.com/youtube/v3/docs/channels

Swineherd answered 19/10, 2015 at 15:38 Comment(4)
This is no longer working. Using channels.list API requesting status part, I query for a channel which shows verified badge on YouTube site, however the value returned by API for the longUploadsStatus flag is "longUploadsUnspecified" not true.Biotope
it returns that response "longUploadsUnspecified" when the request is not properly authorized. (you need a token authed by the channel owner).Swineherd
I am authenticating with a token in the YouTube.Channels.List setKey method, but if the token needs to be authorized for the particular channel it defeats the purpose of identifying verified channels in general search results. FYI, I am using the Java API.Biotope
I've created a feature request for this on Google's bug tracker since it appears the API doesn't currently provide the functionality we are looking for. In case anyone else needs this, please star the issue so we can get some traction issuetracker.google.com/issues/62275991Biotope

© 2022 - 2024 — McMap. All rights reserved.