`q` 参数如何与 YouTube API 一起使用?

How does the `q` parameter work with the YouTube API?

我一直在使用 YouTube 的 API,我对 youtube.search().list() 中的 q 参数的工作原理感到困惑。

一般加一个q参数就相当于设置要搜索的关键字。但是,不添加此参数,API 也会检索视频。

这些视频来自哪里?它们是随机的吗?

根据Google Documentation

string

The q parameter specifies the query term to search for.

Your request can also use the Boolean NOT (-) and OR (|) operators to exclude videos or to find videos that are associated with one of several search terms. For example, to search for videos matching either "boating" or "sailing", set the q parameter value to boating|sailing. Similarly, to search for videos matching either "boating" or "sailing" but not "fishing", set the q parameter value to boating|sailing -fishing. Note that the pipe character must be URL-escaped when it is sent in your API request. The URL-escaped value for the pipe character is %7C.

如果您不添加 q 参数,系统仍会根据您输入的其他参数搜索视频。