获取YouTube视频的每月观看次数

时间:2011-02-20 17:07:51

标签: php json api youtube

我希望有人可以帮忙解决这个问题。基本上,我有一个PHP脚本,显示来自youtube数据json api的youtube视频和统计信息。问题是,我需要能够显示上个月以及当月的总观看次数。我可以获得视频的总观看次数,如果您在YouTube上查看,则视频下方会显示一个图表,其中会显示几个月的观看次数。这可能吗??如果没有,我可以采用其他方式存储前几个月的观看次数吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

运行一个更新每月滴答的cron作业......

您需要做的就是在每月月初存储观看值,并在下个月到达时计算差异。

运行cron作业将确保30天内完成并且值应该更新。

实施例

$lastmonth = 2238923; // 2,238,923views at the start of this month
$currentview = youtubeview(); // However you get the current view 
$thismonth = $lastmonth - $currentview; // Difference and when the month is over $thismonth becomes $lastmonth :)