【问题标题】:Google Custom Search: 403 error in iOSGoogle 自定义搜索:iOS 中的 403 错误
【发布时间】:2014-06-13 19:12:05
【问题描述】:

Google 自定义搜索正在从我的 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。

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

    • 将“q”设置为任何测试查询字词(“foo bar”),将“cx”设置为第 2 步中的搜索引擎 ID。
    • 按“执行”并接收您的搜索结果。他们工作。 Google 还提供了这个 URL,我们将在第 8 步中在 Xcode 中重复使用它。
  4. 要获取用于 ID 和计费目的的密钥,请在 https://console.developers.google.com/ 创建一个新项目

  5. 在 APIs & auth -> APIs -> 启用“自定义搜索 API”。未启用其他 API。

  6. 在 APIs & auth -> Credentials -> 创建一个新的 iOS 密钥。 注意:我还尝试了浏览器密钥,搜索结果返回“错误 400:无效值”。由于我在 iOS 上,所以我返回了 iOS 密钥,并且错误似乎不那么严重。

  7. 将来自 Xcode 的包标识符添加到此键。

  8. 在 Xcode 中,向第 3 步中的 URL 发出 GET 请求。将 {YOUR_API_KEY} 替换为第 6-7 步中凭据中的密钥。

NSData *response 包含上面显示的错误 403。感谢您对问题的任何想法!

【问题讨论】:

  • 我遇到了同样的错误,你有解决办法吗?
  • 感谢提醒!我回答了对我有用的东西。
  • 这个问题确实帮助我弄清楚了完整的过程,这是你需要知道的让它工作的所有内容:stackoverflow.com/a/27039037/656600

标签: ios google-api search-engine google-custom-search


【解决方案1】:

缺少标题字段 X-Ios-Bundle-Identifier

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

【讨论】:

  • 非常感谢!这解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-17
  • 1970-01-01
  • 1970-01-01
  • 2015-01-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多