【发布时间】:2015-02-26 20:40:46
【问题描述】:
这里的概念是数据库将 youtube 频道用户名存储在一个名为 YOUTUBE 的单元格中。
我需要代码来查找 USERDB、查找 YOUTUBE 单元格并检索存储在列表中的所有用户名(任何空白单元格都不会显示)。
从这里开始,我需要将用户 YouTube 用户名从 YOUTUBE 单元格放入 FEEDURL 的代码
我需要这个循环,以便它可以从结果中执行每个单独的用户。我遇到的问题是 FEEDURL 在 URL 中显示所有用户的用户名而不是一个。
EG。 http://gdata.youtube.com/feeds/api/users/PewDiePie,MissFushi/uploads?max-results=13
但我需要它像
EG。 http://gdata.youtube.com/feeds/api/users/MissFushi/uploads?max-results=13
这是我的代码
$communityvideos = mysql_query("SELECT youtube FROM userdb WHERE rights='user' && youtube IS NOT NULL");
while($youtube = mysql_fetch_array($communityvideos)) {
$v[] = $youtube["youtube"];
}
$youtube2 = implode(',', array_filter($v));
$usernames = array($youtube2);
error_reporting(E_ALL);
foreach ($usernames as $user) {
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $user .'/uploads?max-results=13';
$sxml = simplexml_load_file($feedURL);
}
$i=0;
foreach ($sxml->entry as $entry) {
$media = $entry->children('media', true);
$watch = (string)$media->group->player->attributes()->url;
$thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;
parse_str( parse_url( $watch, PHP_URL_QUERY ), $my_array_of_vars);
最后我只想要总共显示 13 个视频。不是来自每个用户的 13 个视频,而是来自所有加入的用户的 13 个视频。有什么想法吗?
【问题讨论】:
-
您正在以某种奇怪的方式编辑数组。让我想出一个可能的解决方案。
标签: php youtube youtube-api