是否有一个字段可以知道youtube频道是否通过youtube API验证



我正在使用Youtube数据API,我需要知道是否有任何方法可以发现Youtube频道是验证频道。

RE:mpgn的解决方案,请注意,是否验证G+帐户和是否验证一个或多个帐户YouTube频道之间存在区别。一个帐户可能有多个频道,每个频道都经过独立验证,即使相关的G+帐户经过验证,频道也可能未经验证。

正如@Paul Blakely所建议的,目前最好的方法是根据https://developers.google.com/youtube/v3/docs/channels

截至2022年11月,YouTube数据API没有提供任何方法来确定给定的YouTube频道是否经过验证。相反,当前产生可靠结果的方法是抓取通道解析一点JSON搜索结果结构

我们将从加载给定频道的服务器响应开始。下面我有一个硬编码为id变量的通道ID:

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

对于我们的响应对象,我们现在应该继续检查是否收到了200 OK,这表明检索页面数据没有问题,并且可以安全地继续:

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

在以下条件下的块中,我们可以开始检索YouTube页面的初始数据。在提供频道页面时,YouTube还将为频道本身提供初始数据,可能是为了加快交付速度等原因。

我们将查找这些初始数据,将其解析为JSON,并筛选结果:

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

解析数据后,我们现在将注意力转向生成结构的一部分,即c4TabbedHeaderRenderer属性。这是存储页面徽章(如验证徽章)的地方。我们还将定义verifiedLabel,以解释我们正在寻找的内容:

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

最后,我们需要确认badges是一个数组(可能不是,如果通道没有可枚举的徽章),然后检查我们的verifiedLabel徽章:

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

此时,verified要么为true(如果通道已验证),要么为false。我希望这能有所帮助!

今天刚刚遇到这个问题,虽然V3 youtube API的channelBranding看起来很有希望,但如果帐户/频道用户id已验证或未,我无法返回它

所以我抛出了一个非常蹩脚的php脚本,它使用DOM模型搜索来直接检查html。如果存在以下元素,则返回true。

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

截至今天(2014年9月8日),已验证的用户将返回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;
    }
}
?>

再见!

在经过验证的通道上,存在类"has badge"。

2018年工作:

<?php
$key = 'has-badge';
$channel = file_get_contents('https://www.youtube.com/...');
if( stripos($channel, $key) !== FALSE )
    echo "Verified";
else
    echo "Not Verified";
?>

如果可以通过允许或符合条件的status.longUploadsStatus标志来检查推断youtube频道的已验证状态,因为目前此功能需要验证相关的youtube帐户。

来源:https://developers.google.com/youtube/v3/docs/channels

最新更新