OGeek|极客世界-中国程序员成长平台

标题: ios - 将 youtube v3 与 apikey 一起使用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:40
标题: ios - 将 youtube v3 与 apikey 一起使用

我正在尝试使用 YouTube v3 API 使用 APIKey 而不是 oAuth2 执行搜索。

我的问题是,当我使用 APIKey 时,查询总是返回错误。

这是初始化服务的代码

_service = [[GTLServiceYouTube alloc] init];
[_service setRetryEnabled:YES];
[_service setAPIKey:kAPIKey];

这是查询的代码

GTLQueryYouTube *query = [GTLQueryYouTube queryForSearchListWithPart"snippet"];
query.q = filter;
query.type = type;
query.maxResults = maxResults;

[_service executeQuery:query completionHandler:
 ^(GTLServiceTicket *ticket, GTLYouTubeSearchListResponse *searchListResponse, NSError *error)
{
//-- do stuff
 }];

使用 APIKey 时返回的错误如下。如果我使用 oAuth,一切都会按预期进行。

error: Error Domain=com.google.GTLJSONRPCErrorDomain Code=403 "The operation couldn’t be completed. (Access Not Configured)" UserInfo=0x13d10ac0 {error=Access Not Configured, GTLStructuredError=GTLErrorObject 0x13d0c770: {message:"Access Not Configured" code:403 data:[1]}, NSLocalizedFailureReason=(Access Not Configured)}

我已在 Google API 控制台上创建了 APIKey,并且服务已启用。



Best Answer-推荐答案


不是理想的解决方案...但我在这篇文章中找到了解决方法: google-youtube-api-v3-ios-app-key-403-error-code

基本上,如果我们使用“浏览器应用程序 key ”而不是“iOS 应用程序 key ”,它将起作用。

关于ios - 将 youtube v3 与 apikey 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15422722/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4