Google自定义search:iOS中有403错误

谷歌自定义search从我的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." } } 

下面的步骤是否有缺陷? 我想build立特定于iOS应用程序的工作CSE设置过程。 在每一步的截图将有望帮助,而不是混淆!

  1. 通过https://www.google.com/cse/创build自定义search引擎(CSE)

  2. 从设置 – >基本,获取search引擎ID。 CSE搜索引擎ID

  3. 在https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list上testingCSE

    • 在步骤2中将“q”设置为search引擎ID的任何testing查询条件(“foo bar”)和“cx”。
    • 按“执行”并接收您的search结果。 他们工作。 谷歌也提供了这个url,我们将在第8步在Xcode中重复使用。 Google API Explorer测试结果
  4. 要使自己成为ID和结算用途的关键,请通过以下url创build新项目: https://console.developers.google.com/

  5. 在API和身份validation – > API – >启用“自定义searchAPI”。 没有其他的API被启用。 开发者控制台API

  6. 在API&auth – > Credentials下 – >创build一个新的iOS密钥。 开发者控制台凭证 注意:我也尝试了浏览器键,search结果返回“错误400:无效值”。 由于我在iOS上,所以我返回了iOS键,错误似乎不那么严重。

  7. 从Xcode中添加此密钥标识符。 Xcode包标识符

  8. 在Xcode中,在步骤3中向您的GET请求发送URL。用步骤6-7中的凭据replace{YOUR_API_KEY}。

GET请求在Xcode

NSData *响应包含上面显示的错误403。 感谢有什么不对的想法!

它缺less标题字段X-Ios-Bundle-Identifier

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