2014-12-19 48 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