通过PHP中的JSON API获取Youtube订阅者数量

elk*_*med 3 php json youtube-api

我想从此JSON文件中获取订阅者计数值:http://gdata.youtube.com/feeds/api/users/googlechrome? v = 2 &alt = json

这就是我所做的,但它不起作用.

$youtube_url = json_decode( file_get_contents( 'http://gdata.youtube.com/feeds/api/users/googlechrome?v=2&alt=json' ), true );
$youtube_data = $youtube_url['entry']['yt$statistics']['subscriberCount'];
Run Code Online (Sandbox Code Playgroud)

小智 5

PHP代码:

function get_yt_subs($username) { 

$xmlData = file_get_contents('http://gdata.youtube.com/feeds/api/users/' . strtolower($username)); 
$xmlData = str_replace('yt:', 'yt', $xmlData); 

$xml = new SimpleXMLElement($xmlData); 

$subs = $xml->ytstatistics['subscriberCount']; 

return($subs); 

}  
Run Code Online (Sandbox Code Playgroud)

用法示例:PHP代码:

get_yt_subs('3moeslam')
Run Code Online (Sandbox Code Playgroud)