谷歌自定义搜索:iOS中出现403错误

6
谷歌自定义搜索在我的iPhone 7.1应用程序中返回了403错误。在模拟器中运行时,这是响应结果:
{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
   }
  ],
  "code": 403,
  "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
 }
}

以下步骤是否有缺陷?我想建立一个特定于iOS应用程序的工作CSE设置过程。每个步骤中的屏幕截图将有助于理解而不会混淆!
  1. https://www.google.com/cse/创建一个自定义搜索引擎(CSE)。

  2. 从“设置” -> “基础知识”获取搜索引擎ID。 CSE search engine ID

  3. https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list测试CSE。

    • 将“q”设置为任何测试查询词(“foo bar”),将“cx”设置为第2步中的搜索引擎ID。
    • 点击“执行”并接收您的搜索结果。它们有效。谷歌还提供了这个URL,我们将在第8步中在Xcode中重新使用它。 Google API Explorer test results
  4. 为了获得ID和计费目的的密钥,请在https://console.developers.google.com/中创建一个新项目。

  5. 在API和身份验证 -> API下启用“自定义搜索API”。没有启用其他API。 Developer Console APIs

  6. 在API和身份验证 -> 凭据下创建一个新的iOS密钥。 Developer Console Credentials 注意:我还尝试了一个浏览器密钥,但搜索结果返回“错误400:无效值”。由于我在iOS上,错误似乎不那么严重,因此我返回到iOS密钥。

  7. 将Xcode的bundle标识符添加到此密钥中。 Xcode bundle identifier

  8. 在Xcode中对步骤3中的URL进行GET请求。将{YOUR_API_KEY}替换为步骤6-7中凭据中的密钥。

GET request in Xcode

NSData *response包含了上面显示的403错误。感谢任何关于问题出在哪里的想法!


我也遇到了同样的错误,你找到解决方案了吗? - Suhit Patil
谢谢提醒!我回答了我所知道的方法。 - Orbusii
1
这个问题确实帮助我弄清了整个过程,以下是你需要知道的所有内容才能使其正常工作:https://dev59.com/fl8d5IYBdhLWcg3wNQRg#27039037 - rptwsthi
1个回答

6

缺少头字段 X-Ios-Bundle-Identifier

NSString *bundleID = @"com.yourCompany.yourApp";
//...define request as above
[request setHTTPMethod:@"GET"];
[request setValue:bundleID forHTTPHeaderField:@"X-Ios-Bundle-Identifier"];

非常感谢!这解决了我的问题。 - Joshua

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接