从 YouTube 的视频列表中获取视频数据 API 带来了错误的数据
Fetching Video data from YouTube's video list API bringing wrong data
在 Videos.list
API 的参数中,有一个必需参数列表,其中必须为要获取的数据选择一个过滤器参数。参数是 chart
、id
和 myRating
,我不需要任何参数,因为我没有视频 ID 也无法访问用户评分(我只想获取视频).
所以我要做的是选择 chart
并将其设置为 mostPopular
,如下所示:
class App extends React.Component{
onSubmitForm=async (text)=>{
const key= {my actual key}
const response = await axios.get(
'https://www.googleapis.com/youtube/v3/videos',
{
params: {
part:'snippet',
maxResults :10,
type: 'video',
chart:'mostPopular'
key,
q: text,
},
})
}
但是,这 returns 只有 10 个最受欢迎的视频,没有 我在 text
搜索词中输入的任何内容。
所以总而言之,如果我不使用过滤器参数 chart
、id
和 myRating
之一,而当我使用 chart
时,它会抛出一个错误调出与我的搜索查询无关的热门视频。我该如何导航?
你必须承认Videos.list
API endpoint has no q
parameter. You may well confuse it with the request parameter q
of another API endpoint, that of Search.list
。
因此,您有两个正交选项:要么使用 Videos.list
查询参数 chart=mostPopular
与 regionCode
and videoCategoryId
串联。或者,否则,根据需要使用使用参数 q
查询的 Search.list
。
在 Videos.list
API 的参数中,有一个必需参数列表,其中必须为要获取的数据选择一个过滤器参数。参数是 chart
、id
和 myRating
,我不需要任何参数,因为我没有视频 ID 也无法访问用户评分(我只想获取视频).
所以我要做的是选择 chart
并将其设置为 mostPopular
,如下所示:
class App extends React.Component{
onSubmitForm=async (text)=>{
const key= {my actual key}
const response = await axios.get(
'https://www.googleapis.com/youtube/v3/videos',
{
params: {
part:'snippet',
maxResults :10,
type: 'video',
chart:'mostPopular'
key,
q: text,
},
})
}
但是,这 returns 只有 10 个最受欢迎的视频,没有 我在 text
搜索词中输入的任何内容。
所以总而言之,如果我不使用过滤器参数 chart
、id
和 myRating
之一,而当我使用 chart
时,它会抛出一个错误调出与我的搜索查询无关的热门视频。我该如何导航?
你必须承认Videos.list
API endpoint has no q
parameter. You may well confuse it with the request parameter q
of another API endpoint, that of Search.list
。
因此,您有两个正交选项:要么使用 Videos.list
查询参数 chart=mostPopular
与 regionCode
and videoCategoryId
串联。或者,否则,根据需要使用使用参数 q
查询的 Search.list
。