我正在尝试使用 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,并且该服务已启用。