【发布时间】:2020-05-18 05:30:41
【问题描述】:
我正在将 YouTube 视频嵌入到我正在编写的应用中,但其中一些结果是不允许在我的网站上播放的视频。我尝试在参数中将 videoSyndicated 和 videoEmbeddable 都设置为 true,但它似乎无法解决我的问题。
const axios = require('axios');
const ROOT_URL = 'https://www.googleapis.com/youtube/v3/search';
const search = (options, callback) => {
if(!options.key) {
throw new Error('Youtube Search expected key, received undefined');
}
const params = {
type: 'video',
videoEmbeddable: true,
videoSyndicated: true,
part: 'snippet',
key: options.key,
q: options.term,
};
axios.get(ROOT_URL, { params })
.then((response) => {
if(callback) { callback(response.data.items); }
})
.catch((error) => {
console.error(error);
});
};
export default search;`
【问题讨论】:
-
一个示例搜索可能和一个无法播放的示例视频?以及您从查询中获得的示例结果集?请提供minimal reproducible example。
-
另外,检查视频是否可以嵌入 - see these search results.