pro*_*ody 16 youtube-api youtube-channels
我正在使用Youtube数据API,我需要知道是否有任何方法可以找到youtube频道是已验证的频道.
今天刚刚遇到这个问题,虽然V3 youtube API 的频道品牌看起来很有希望,但如果帐户/频道用户 ID 是否经过验证,我无法让它返回
所以我写了一个相当蹩脚的 php 脚本,它使用 DOM 模型搜索来直接检查 html。如果存在以下元素则返回 true。
<a href="//support.google.com/youtube/bin/answer.py?answer=3046484&hl=en" class="qualified-channel-title-badge" target="_blank">
Run Code Online (Sandbox Code Playgroud)
从今天(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;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
暂时再见!
| 归档时间: |
|
| 查看次数: |
3158 次 |
| 最近记录: |