YouTube API "ChannelSections" 结果与频道不匹配?

YouTube API "ChannelSections" results don't match with channel?

对于 YouTube 频道 Mindless Self Indulgence,它在主页选项卡上有 4 个部分,第一个部分是音乐视频播放列表,第二个部分是专辑,这是一组不同的播放列表,然后是另一个播放列表部分和最后一节是上传。

但是当我执行 channelSections api 调用时,我得到了大约 20 个不同的项目,这让我摸不着头脑。

这是 api 回复 https://notepad.pw/raw/w27ot290s

https://www.googleapis.com/youtube/v3/channelSections?key={KEYHERE}&channelId=UChS8bULfMVx10SiyZyeTszw&part=snippet,contentDetails

所以我终于想通了,我忘记阅读有关 channelSections 的文档 api

此处:https://developers.google.com/youtube/v3/docs/channelSections

我正在获取所有地区的频道部分,在这些地区,像音乐这样的频道可能更经常有区域特定的部分...要过滤这些,您还需要在部分参数中包含目标对象。如果该部分是无区域的(或者至少我假设),它将没有目标对象,因此在处理您的 api 响应和基于区域的过滤部分时需要考虑一些事情。

这是我的代码,只是试图在 React 应用程序中过滤数据,可能不是最实用的,但我摸索了一下:

const data = response2.data.items;
console.log("response2 data", data);
const filtered = data.filter(item => {
    if (item.targeting === undefined) return true;
    let test = false;
    item.targeting.countries.forEach(i => {
        if (i === "US") test = true;
    });
    return test;
});