我使用的是从Google开发者网站截取的以下代码。它工作得很好,但是当我搜索术语shukareh alla
时,得到的结果为零。这个术语实际上是拼写错误的,但是我想得到拼写错误的术语的结果,就像YouTube网站为我提供上述术语的结果一样。我不知道我是否应该为它指定一些额外的参数,或者YouTube API不提供这个功能?你知道吗
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.tools import argparser
DEVELOPER_KEY = "***************"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
def youtube_search(options):
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
developerKey=DEVELOPER_KEY)
# Call the search.list method to retrieve results matching the specified
# query term.
search_response = youtube.search().list(
q=options.q,
part="id,snippet",
maxResults=options.max_results
).execute()
videos = []
channels = []
playlists = []
# Add each result to the appropriate list, and then display the lists of
# matching videos, channels, and playlists.
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
videos.append("%s (%s)" % (search_result["snippet"]["title"],
search_result["id"]["videoId"]))
elif search_result["id"]["kind"] == "youtube#channel":
channels.append("%s (%s)" % (search_result["snippet"]["title"],
search_result["id"]["channelId"]))
elif search_result["id"]["kind"] == "youtube#playlist":
playlists.append("%s (%s)" % (search_result["snippet"]["title"],
search_result["id"]["playlistId"]))
print "Videos:\n", "\n".join(videos), "\n"
print "Channels:\n", "\n".join(channels), "\n"
print "Playlists:\n", "\n".join(playlists), "\n"
if __name__ == "__main__":
argparser.add_argument("--q", help="Search term", default="shukareh alla")
argparser.add_argument("--max-results", help="Max results", default=10)
args = argparser.parse_args()
try:
youtube_search(args)
except HttpError, e:
print "An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)
正如DaImTo所说,youtubeapi不提供任何拼写检查搜索功能。我可以使用Google Custom Search Engine API进行拼写检查。我已经为“站点”创建了一个自定义站点搜索引擎youtube.com网站". 每当我的Youtube搜索结果为零(使用youtubeapi),我就使用自定义搜索API来搜索相同的关键字。自定义搜索引擎API最好的地方是,如果搜索关键字的结果为零,并且搜索关键字不正确,它将执行拼写检查并返回正确的搜索查询。你知道吗
对我来说好像有0个结果。你知道吗
Search: list返回与API请求中指定的查询参数匹配的搜索结果集合。你知道吗
YouTube API将返回您发送的请求的所有结果。它不会为你检查拼写。您的应用程序必须检查拼写,然后将正确的拼写发送到YouTube API。你知道吗
答案:YouTube API不提供拼写检查搜索功能。你知道吗
相关问题 更多 >
编程相关推荐