2014-12-19 85 views
5

我在我的iOS应用中集成了Google URL-Shorten API,仅用于测试目的。 我的应用程序的套件ID由我添加到Authorized iOS Applications的列表中以发送请求。accessNotConfigured:谷歌URL在iOS模拟器上缩短API

但每当我发送使用NSURLRequestHTTPPOST要求,我得到了以下错误响应JSON

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "usageLimits", 
    "reason": "accessNotConfigured", 
    "message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.", 
    "extendedHelp": "https://console.developers.google.com" 
    } 
    ], 
    "code": 403, 
    "message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration." 
} 
} 

我无法弄清楚如何解决这个问题。一个猜测我做了是“可能是我不得不使用API​​的在线应用程序”

支持参考我的猜测是从API文档

If your application accesses APIs directly from iOS, you will need the application's Bundle ID and (optionally) its Apple App Store ID: 

The application's Bundle ID is the bundle identifier as listed in the app's .plist file. For example: com.example.myapp. 
The application's App Store ID is in the app's iTunes URL so long as the app was published in the Apple iTunes App Store. For example, in the app URL http://itunes.apple.com/us/app/google+/id447119634, the App Store ID is 447119634. 

回答

1

由于错误状态还没有正确配置访问API或您未验证应用程序。

Authorizing requests and identifying your application

每个请求您的应用程序发送给谷歌URL缩短API 需要确定您的应用程序谷歌。 有两种方式可以识别您的应用程序:使用OAuth 2.0令牌(也可以 授权请求)和/或使用应用程序的API密钥。下面是 如何确定要使用的这些选项:

您需要设置在Google Developer console项目启用URL Shorter API,并请使用API​​密钥来访问它或OAuth2用户。

0

您可能错过了传递API密钥。你可以看到如何通过钥匙here

3

当您设置API密钥时,除非您使用OAuth 2.0,否则不要提供可选的iOS捆绑ID。 Google API Keys for iOS Usage

我遇到了同样的错误,删除了捆绑ID并清除了403,同时仍然在使用NSURLSession的HTTP POST请求上使用API​​密钥。

您可以通过访问Google开发者控制台,单击API & auth下的“凭据”,然后单击API密钥名称来删除该错误。然后,您将获得一个屏幕,您可以在其中删除与API密钥关联的iOS捆绑软件ID。然后点击保存按钮,然后重新测试。

+0

它只是工作! – Dashrath 2016-06-04 10:45:22