在创建新密钥并删除旧密钥后,我在 iOS Xcode 项目中使用 Google Maps SDK for iOS 的无限制 api 密钥
I am using an unrestricted api key for Google Maps SDK for iOS with my iOS Xcode project after having created a new key and deleting the old key
我在 iOS Xcode 项目中使用 Google Maps SDK for iOS 的无限制 api 密钥创建新密钥后删除旧密钥,但我的请求被拒绝。之前我用第一个键的时候就成功了。
错误信息如下:
[error_message: This API project is not authorized to use this API., status: REQUEST_DENIED, routes: <__NSArrayM 0x60000097f5d0>(
)
这是我在 AppDelegate 中的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GMSServices.provideAPIKey("***")
GMSPlacesClient.provideAPIKey("***")
}
这是我的代码,其中我 运行 请求:
let directionsURLString = "https://maps.googleapis.com/maps/api/directions/json?origin=1%20Cuntry%20Club%20Ln,%20Texarkana,%20AR&destination=1%20Cuntry%20Club%20Ln,%20Texarkana,%20AR&waypoints=optimize:true%7C921%20Orleans%20St,%20Texarkana,%20AR%7C2510%20E.%2011th%20St.,%20Texarkana,%20AR%2071846%7C4125%20Lynn%20Dr,%20Texarkana,%20TX%7C6002%20Yorktown%20Pl,%20Texarkana,%20TX%7C7007%20Stonewall%20Dr,%20Texarkana,%20TX%7C4009%20Constitution%20Dr,%20Texarkana,%20TX%7C413%20Dundee%20Rd,%20Texarkana,%20AR%7C2219%20Hazel%20St,%20Texarkana,%20TX%7C414%20Central%20Ave,%20Wake%20Village,%20TX&mode=driving&key=***"
let directionsURL = URL(string: directionsURLString)!
DispatchQueue.main.async {
do {
let directionsData = try Data(contentsOf: directionsURL)
let dictionary: Dictionary<NSObject, AnyObject> = try JSONSerialization.jsonObject(with: directionsData, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<NSObject, AnyObject>
print(dictionary)
let status = dictionary["status" as NSObject] as! String
print("status=" + status)
} catch {
print(error)
}
}
如果您的 API 密钥确实完全不受限制,那么您遇到的这个 REQUEST_DENIED 错误可能意味着以下内容:
A) 与您的项目相关联的结算帐户存在问题,或者您没有 created 一个。请仔细检查您的结算帐户是否已启用且信誉良好。
B) 方向 API 在您的项目中被禁用。要启用它,请查看 this guide.
希望对您有所帮助!
我在 iOS Xcode 项目中使用 Google Maps SDK for iOS 的无限制 api 密钥创建新密钥后删除旧密钥,但我的请求被拒绝。之前我用第一个键的时候就成功了。
错误信息如下:
[error_message: This API project is not authorized to use this API., status: REQUEST_DENIED, routes: <__NSArrayM 0x60000097f5d0>(
)
这是我在 AppDelegate 中的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GMSServices.provideAPIKey("***")
GMSPlacesClient.provideAPIKey("***")
}
这是我的代码,其中我 运行 请求:
let directionsURLString = "https://maps.googleapis.com/maps/api/directions/json?origin=1%20Cuntry%20Club%20Ln,%20Texarkana,%20AR&destination=1%20Cuntry%20Club%20Ln,%20Texarkana,%20AR&waypoints=optimize:true%7C921%20Orleans%20St,%20Texarkana,%20AR%7C2510%20E.%2011th%20St.,%20Texarkana,%20AR%2071846%7C4125%20Lynn%20Dr,%20Texarkana,%20TX%7C6002%20Yorktown%20Pl,%20Texarkana,%20TX%7C7007%20Stonewall%20Dr,%20Texarkana,%20TX%7C4009%20Constitution%20Dr,%20Texarkana,%20TX%7C413%20Dundee%20Rd,%20Texarkana,%20AR%7C2219%20Hazel%20St,%20Texarkana,%20TX%7C414%20Central%20Ave,%20Wake%20Village,%20TX&mode=driving&key=***"
let directionsURL = URL(string: directionsURLString)!
DispatchQueue.main.async {
do {
let directionsData = try Data(contentsOf: directionsURL)
let dictionary: Dictionary<NSObject, AnyObject> = try JSONSerialization.jsonObject(with: directionsData, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<NSObject, AnyObject>
print(dictionary)
let status = dictionary["status" as NSObject] as! String
print("status=" + status)
} catch {
print(error)
}
}
如果您的 API 密钥确实完全不受限制,那么您遇到的这个 REQUEST_DENIED 错误可能意味着以下内容:
A) 与您的项目相关联的结算帐户存在问题,或者您没有 created 一个。请仔细检查您的结算帐户是否已启用且信誉良好。
B) 方向 API 在您的项目中被禁用。要启用它,请查看 this guide.
希望对您有所帮助!