首页 > 解决方案 > 如何使用 php 将 youtube api 数据转换为 xml 数据提要?

问题描述

我有一个想法来转换这个 JSON 数据:

https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&maxResults=50&regionCode=us&videoCategoryId=10&key=Mykey

到 xml ,用于提要 Rss 阅读器

如何仅使用 PHP 做到这一点?

我的尊敬

标签: phpjsonxmlyoutube

解决方案


Youtube API 只返回 JSON。您可以在代码中加载 json 并使用实现自己的 XML

header('Content-type: text/xml');
// other headers are required
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

echo '<xml>';
// Your data
echo '</xml>';

推荐阅读