通过Json显示视频计数(Show Video Count Via Json)

编程入门 行业动态 更新时间:2024-10-26 03:21:55
通过Json显示视频计数(Show Video Count Via Json)

所以我一直用imagecreatepng制作一个动态签名,我正在使用的API是

(假设用户名是“googlechrome”)

http://gdata.youtube.com/feeds/api/users/googlechrome?v=2&alt=json

这一行告诉我他们有289个视频:

{"rel":"http://gdata.youtube.com/schemas/2007#user.uploads","href":"http://gdata.youtube.com/feeds/api/users/googlechrome/uploads?v=2","countHint":289},

我不确定如何在图像上打印出来。

我的代码到目前为止。

语法:domain.com/image.php?channel=googlechrome

yt.png = http://i.imgur.com/OCRWhI6.png

<?php $channel = $_REQUEST["channel"]; $image = ('yt.png'); $im = imagecreatefrompng($image); $white = imagecolorallocate($im, 255, 255, 255); $width = imagesx($im); $height = imagesy($im); $font = 2; $json_output = file_get_contents('http://gdata.youtube.com/feeds/api/users/'.($channel).'?v=2&alt=json'); $json = json_decode($json_output, true); $username = $json['entry']['yt$username']['$t']; $view_count = $json['entry']['yt$statistics']['totalUploadViews']; $sub_count = $json['entry']['yt$statistics']['subscriberCount']; //$video_count = $json['entry']['DUNNO_YET']['$t']; $UserName = ("".$username); imagestring($im, $font, $width-190, $height-59, $UserName, $white); $viewCount = ("".$view_count); imagestring($im, $font, $width-190, $height-45, $viewCount, $white); $subCount = ("".$sub_count); imagestring($im, $font, $width-190, $height-30, $subCount, $white); $VideoCount = ("".$video_count); imagestring($im, $font, $width-190, $height-15, $VideoCount, $white); //text before counts $UNAME = ('Username:'); imagestring($im, $font, $width-278, $height-59, $UNAME, $white); $TOTALVIEWS = ('Total Views: '); imagestring($im, $font, $width-278, $height-45, $TOTALVIEWS, $white); $SUBS = ('Subscribers: '); imagestring($im, $font, $width-278, $height-30, $SUBS, $white); $TOTALVIDEOS = ('Total Videos: '); imagestring($im, $font, $width-278, $height-15, $TOTALVIDEOS, $white); Header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?>

任何帮助赞赏!

So I've been making a dynamic signature with imagecreatepng, The API I'm using is

(Assuming the username is "googlechrome")

http://gdata.youtube.com/feeds/api/users/googlechrome?v=2&alt=json

This line shows me they have 289 videos:

{"rel":"http://gdata.youtube.com/schemas/2007#user.uploads","href":"http://gdata.youtube.com/feeds/api/users/googlechrome/uploads?v=2","countHint":289},

I am unsure about how to print it out on the image.

My code so far.

Syntax: domain.com/image.php?channel=googlechrome

yt.png = http://i.imgur.com/OCRWhI6.png

<?php $channel = $_REQUEST["channel"]; $image = ('yt.png'); $im = imagecreatefrompng($image); $white = imagecolorallocate($im, 255, 255, 255); $width = imagesx($im); $height = imagesy($im); $font = 2; $json_output = file_get_contents('http://gdata.youtube.com/feeds/api/users/'.($channel).'?v=2&alt=json'); $json = json_decode($json_output, true); $username = $json['entry']['yt$username']['$t']; $view_count = $json['entry']['yt$statistics']['totalUploadViews']; $sub_count = $json['entry']['yt$statistics']['subscriberCount']; //$video_count = $json['entry']['DUNNO_YET']['$t']; $UserName = ("".$username); imagestring($im, $font, $width-190, $height-59, $UserName, $white); $viewCount = ("".$view_count); imagestring($im, $font, $width-190, $height-45, $viewCount, $white); $subCount = ("".$sub_count); imagestring($im, $font, $width-190, $height-30, $subCount, $white); $VideoCount = ("".$video_count); imagestring($im, $font, $width-190, $height-15, $VideoCount, $white); //text before counts $UNAME = ('Username:'); imagestring($im, $font, $width-278, $height-59, $UNAME, $white); $TOTALVIEWS = ('Total Views: '); imagestring($im, $font, $width-278, $height-45, $TOTALVIEWS, $white); $SUBS = ('Subscribers: '); imagestring($im, $font, $width-278, $height-30, $SUBS, $white); $TOTALVIDEOS = ('Total Videos: '); imagestring($im, $font, $width-278, $height-15, $TOTALVIDEOS, $white); Header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?>

Any Help appreciated!

最满意答案

$video_count变量应该等于:

$video_count = $json['entry']['gd$feedLink'][6]['countHint'];

但是,我不确定上传计数是否总是在gd$feedLink的第6个索引处,所以使用类似下面的内容可能是一个明智的想法:

$video_count = 0; foreach ($json['entry']['gd$feedLink'] as $feed) { if ($feed['rel'] == 'http://gdata.youtube.com/schemas/2007#user.uploads') { $video_count = $feed['countHint']; break; } }

The $video_count variable should be equal to:

$video_count = $json['entry']['gd$feedLink'][6]['countHint'];

However, I am unsure if the upload count will always be at the 6th index of gd$feedLink, so it may be a smart idea to use something like the following instead:

$video_count = 0; foreach ($json['entry']['gd$feedLink'] as $feed) { if ($feed['rel'] == 'http://gdata.youtube.com/schemas/2007#user.uploads') { $video_count = $feed['countHint']; break; } }

更多推荐

本文发布于:2023-07-31 09:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1341921.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   Json   Show   Count   Video

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!