Google 自定义搜索:iOS 中的 403 错误 [英] Google Custom Search: 403 error in iOS

查看:43
本文介绍了Google 自定义搜索:iOS 中的 403 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 自定义搜索从我的 iPhone 7.1 应用返回了这个 403 错误.这是在模拟器中运行时的响应:

<代码>{错误": {错误":[{"domain": "usageLimits","reason": "accessNotConfigured","message": "访问权限未配置.请使用 Google Developers Console 为您的项目激活 API."}],代码":403,"message": "访问权限未配置.请使用 Google Developers Console 为您的项目激活 API."}}

下面的步骤有问题吗?我想建立一个特定于 iOS 应用程序的有效 CSE 设置过程.每个步骤的屏幕截图希望能有所帮助而不是混淆!

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

  2. 在 API 下 &auth -> APIs -> 启用自定义搜索 API".未启用其他 API.

  3. 在 API 下 &auth -> Credentials -> 创建一个新的 iOS 密钥.注意:我还尝试了浏览器键,搜索结果返回错误 400:无效值".由于我使用的是 iOS,因此我返回了 iOS 密钥,但错误似乎不那么严重.

  4. 将来自 Xcode 的包标识符添加到此密钥.

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

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

解决方案

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

NSString *bundleID = @"com.yourCompany.yourApp";//...定义请求如上[请求 setHTTPMethod:@"GET"];[请求 setValue:bundleID forHTTPHeaderField:@"X-Ios-Bundle-Identifier"];

Google Custom Search is returning this 403 error from my iPhone 7.1 app. This is the response when run in the simulator:

{
 "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."
 }
}

Is there a flaw in the steps below? I’d like to establish a working CSE setup process specific to iOS apps. The screenshots at each step will hopefully help and not confuse!

  1. Create a Custom Search Engine (CSE) at https://www.google.com/cse/

  2. From Setup -> Basics, get the Search engine ID.

  3. Test the CSE at https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list

    • Set "q" to any test query terms ("foo bar") and "cx" to the Search engine ID in step 2.
    • Press "Execute" and receive your search results. They work. Google also provides this URL which we'll re-use in Xcode in step 8.
  4. To get ourselves a key for ID and billing purposes, create a new project at https://console.developers.google.com/

  5. Under APIs & auth -> APIs -> Enable "Custom Search API." No other APIs are enabled.

  6. Under APIs & auth -> Credentials -> Create a new iOS key. Note: I also tried a browser key and the search result returned "Error 400: Invalid Value." I returned to the iOS key since I'm on iOS and the error seemed less severe.

  7. Add to this key your bundle identifier from Xcode.

  8. In Xcode make your GET request to the URL in step 3. Replace {YOUR_API_KEY} with the key from your credentials in steps 6-7.

NSData *response contains the error 403 shown above. Thanks for any thoughts on what's wrong!

解决方案

It was missing the header field X-Ios-Bundle-Identifier.

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

这篇关于Google 自定义搜索:iOS 中的 403 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆