我一直在尝试在我连接的特定 channel 上搜索与几个关键字之一相匹配的视频。我正在使用 Officiel PHP SDK,这就是我所拥有的:
//client is a connected Google_Client
$youtube = new Google_Service_YouTube($client);
$pageToken = null;
$res = $youtube->search->listSearch(
'id, snippet', [
'maxResults' => 50,
'q' => "foo|bar",
'forMine' => true,
'type' => 'video',
'pageToken' => $pageToken
]
);
这将只返回包含“foo”和“bar”的视频,而不是“foo”或“bar”。我也尝试过“foo | bar”、“foo%7Cbar”、“urlencode("foo|bar)"、“foo||bar”,但这些都没有给我想要的东西。
我错过了什么吗?
谢谢。
最佳答案
来自documentation :
To search for videos matching either "boating" or "sailing", set the q parameter value to boating|sailing.
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.
刚刚测试了您的案例,它按预期工作,title
列包含“foo”或“bar”。
"title": "KING OF THE BAR 2015 - Ultimate Calisthenics Battle!",
...
"title": "Foo Fighters",
...
"title": "Foo Fighters - Something From Nothing",
...
"title": "Browning BAR M1918",
...
"title": "Bar \"u Szwagra\" - Video Dowcip",
所以,问题应该在 PHP SDK 中。
关于php - bool OR 似乎在 Youtube APIv3 列表搜索(或 PHP SDK)中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30704660/