2013-12-10 116 views

回答

1

恰好碰到了這個的今天,而channelBranding of the V3 youtube API看起來很有希望,我不能讓它返回如果帳戶/頻道的用戶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; 
    } 
} 
?> 

那再見了!

0

如果可以通過status.longUploadsStatus標誌允許或有資格檢查推斷YouTube頻道的驗證狀態,因爲當前此功能需要驗證關聯的youtube帳戶。

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

+0

這不再工作。使用channels.list API請求狀態部分,我查詢在YouTube網站上顯示驗證徽章的頻道,但API返回的longUploadsStatus標誌的值爲「longUploadsUnspecified」,不正確。 – cheino

+0

它在請求沒有被正確授權時返回那個響應「longUploadsUnspecified」。 (您需要渠道所有者驗證令牌)。 –

+1

我使用YouTube.Channels.List setKey方法中的令牌進行身份驗證,但是如果令牌需要針對特定​​頻道進行授權,則會違反在一般搜索結果中識別驗證頻道的目的。僅供參考,我正在使用Java API。 – cheino

3

一個適當的解決方案,你需要做的這兩步:

STEP 1,使用YouTube數據API V3和ressource channel.list與參數:

part:contentDetails 
id:CHANNEL_ID // or forUsername:USERNAME 

這是輸出:

{ 
    "kind": "youtube#channel", 
    "etag": "\"CuSCwMPVmgi8taDtE2LV6HdgkN0/Mu0u2QSDqnFcBvUF5X21CnGSEac\"", 
    "id": "UCa10nxShhzNrCE1o2ZOPztg", 
    "contentDetails": { 
    "relatedPlaylists": { 
    "uploads": "UUa10nxShhzNrCE1o2ZOPztg" 
    }, 
    "googlePlusUserId": "105350456099841048474" 
    } 
    } 

更多在:https://developers.google.com/youtube/v3/docs/channels/list

STEP 2與谷歌加API,請從以前的請求的googlePlusUserId,並使用資源plus.people.get與參數:

userId:105350456099841048474 

結果將會顯示:

"isPlusUser": true, 
"plusOneCount": 215098, 
"circledByCount": 12621, 
"verified": true, 

驗證字段是你想要的!

更多:https://developers.google.com/+/web/api/rest/latest/people/get

+2

googlePlusUserId字段已被棄用和刪除,並且不再在contentDetails對象中提供。 – cheino

0

RE:MPGN溶液,注意,有之間的G +賬號是否完成認證和是否有一個或多個YouTube頻道恪帳目區別。一個帳戶可以擁有多個頻道,並且每個頻道都是獨立驗證的,即使關聯的G +帳戶已通過驗證,頻道也不會被驗證。

正如@保羅布萊克利指出,要做到這一點目前最好的辦法是檢查status.longUploadStatus標誌,每https://developers.google.com/youtube/v3/docs/channels

1

在經過認證的渠道,類「有徽章」是存在的。

在2018年的工作:

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

if(stripos($channel, $key) !== FALSE) 
    echo "Verified"; 
else 
    echo "Not Verified"; 
?> 
相關問題