2013-03-15 75 views
1

我正尝试使用YouTube v3 API执行使用API​​Key而不是oAuth2的搜索。使用youtube v3 with apikey

我的问题是,当我使用API​​Key时,查询总是返回一个错误。

这是查询

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 
}]; 

使用API​​Key时是下面的例返回错误初始化服务

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

代码,这个代码。如果我使用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,并且该服务已启用。

回答

1

不理想的解决方案......但我发现这个职位的解决方法: google-youtube-api-v3-ios-app-key-403-error-code

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

+0

我使用了评论者的解决方案。它令我感到震惊,这是有效的。 – Morkrom 2013-11-11 08:20:48

0

您是否已经在服务面板的google-console中切换了youtube API?

+0

正如我在早期说的...是的,它启用:) – 2013-03-15 11:34:14

+0

我一直在iphone上搜索你管视频列表。但我没有使用GLService.I不知道为什么你的API密钥不工作。但是您可以从Google控制台生成另一个API密钥。 – 2013-03-16 05:27:27

+0

我已经生成了第二个密钥,结果是相同的。 – 2013-03-16 18:00:50