调用iTunes Podcast Lookup接口获取Feed URL返回空结果求助
解决iTunes Podcast Lookup接口返回空结果并获取Feed URL的方法
问题根源
- 请求方式错误:iTunes的
lookup接口仅支持GET请求,原代码使用POST,导致接口无法正确解析参数。 - 参数与ID不匹配:若传入的是频道ID(如示例中的6442462434),需指定对应参数才能查询有效信息;且频道本身无统一RSS Feed,需获取频道下单个播客的ID后再查询其Feed URL。
修正步骤
1. 切换为GET请求
将请求方式改为GET,参数直接拼接在URL后,无需设置Content-Type请求头。
2. 正确提取并使用ID
- 单个播客链接:从
https://podcasts.apple.com/us/podcast/xxx/id123456789这类链接中提取最后的数字ID(如123456789),直接用id=xxx查询。 - 频道链接:先查询频道信息获取旗下播客列表,再从中提取单个播客的ID查询Feed URL。
修正后的代码示例
情况1:查询单个播客的Feed URL
const podcastId = "123456789"; // 替换为目标单个播客的ID const url = `https://itunes.apple.com/lookup?id=${podcastId}`; const xhrRequest = new XMLHttpRequest(); xhrRequest.onreadystatechange = function() { if (xhrRequest.readyState === 4 && xhrRequest.status === 200) { const response = JSON.parse(xhrRequest.responseText); if (response.resultCount > 0) { const feedUrl = response.results[0].feedUrl; console.log("播客Feed URL:", feedUrl); // 此处可添加Feed URL的解析逻辑 } } }; xhrRequest.onerror = function(e) { console.error("请求出错:", e); }; xhrRequest.open('GET', url); xhrRequest.send();
情况2:从频道获取旗下播客的Feed URL
const channelId = "6442462434"; // 示例中的频道ID const url = `https://itunes.apple.com/lookup?id=${channelId}&entity=podcast`; const xhrRequest = new XMLHttpRequest(); xhrRequest.onreadystatechange = function() { if (xhrRequest.readyState === 4 && xhrRequest.status === 200) { const response = JSON.parse(xhrRequest.responseText); if (response.resultCount > 0) { // 获取频道下首个播客的Feed URL const firstPodcastFeedUrl = response.results[0].feedUrl; console.log("频道下首个播客Feed URL:", firstPodcastFeedUrl); // 遍历输出频道下所有播客的Feed URL response.results.forEach(podcast => { console.log(`${podcast.collectionName}: ${podcast.feedUrl}`); }); } } }; xhrRequest.onerror = function(e) { console.error("请求出错:", e); }; xhrRequest.open('GET', url); xhrRequest.send();
关键说明
- 查询频道时,添加
entity=podcast参数可返回频道下的所有播客条目,每个条目包含feedUrl字段,即该播客的RSS Feed地址。 - 确保ID提取准确:从Apple Podcast链接中提取的数字ID需对应正确的资源类型(播客/频道)。
内容的提问来源于stack exchange,提问作者Toniq
相关产品推荐
相关产品推荐

