Youtube 频道订阅人数 [英] Youtube channel subscriber count

查看:28
本文介绍了Youtube 频道订阅人数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取特定 YouTube 频道的订阅者数量.我参考了 Stackoverflow 和外部网站上的一些链接,遇到了类似 this.几乎所有链接都建议我使用 youtube gdata api 并从subscriberCount 中提取计数,但以下代码

I'm trying to pull the count of subscribers for a particular youtube channel. I referred some links on Stackoverflow as well as external sites, came across links like this. Almost all the links suggested me to use youtube gdata api and pull the count from subscriberCount but the following code

$data   = file_get_contents("http://gdata.youtube.com/feeds/api/users/Tollywood/playlists");
$xml    = simplexml_load_string($data);

print_r($xml);

print_r($xml);

不返回这样的subscriberCount.有没有其他方法可以让订阅者计数,或者我做错了什么?

returns no such subscriberCount. Is there any other way of getting subscribers count or am I doing something wrong?

推荐答案

试试这个 ;)

<?php 
$data = file_get_contents('http://gdata.youtube.com/feeds/api/users/Tollywood');

$xml = new SimpleXMLElement($data);
$stats_data = (array)$xml->children('yt', true)->statistics->attributes();
$stats_data = $stats_data['@attributes'];

/********* OR **********/

$data = file_get_contents('http://gdata.youtube.com/feeds/api/users/Tollywood?alt=json');
$data = json_decode($data, true);
$stats_data = $data['entry']['yt$statistics'];

/**********************************************************/

echo 'lastWebAccess = '.$stats_data['lastWebAccess'].'<br />';
echo 'subscriberCount = '.$stats_data['subscriberCount'].'<br />';
echo 'videoWatchCount = '.$stats_data['videoWatchCount'].'<br />';
echo 'viewCount = '.$stats_data['viewCount'].'<br />';
echo 'totalUploadViews = '.$stats_data['totalUploadViews'].'<br />';
?>

这篇关于Youtube 频道订阅人数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆