google 个位置 iOS 个空引荐来源网址
google places for iOS empty referrer
我在 google 地图 sdk 和地点 api 上工作得很好。昨天我的代码 运行 非常好。但今天早上醒来,做了一些修改,然后 运行 变成了一个滚雪球般的问题,这看起来很容易解决,但花了几个小时试图弄清楚发生了什么。我正在尝试开发一个 iPhone 应用程序。
我回去了,在开发者控制台创建了一个"new project"
重新生成了一个新的 iOS 密钥。
在 info.plist 中输入了新的包 ID
在委托文件和 url.
的搜索参数中输入新的 api 键
我正在使用 alamofire 和 swiftyjson 来解析数据
但仍然遇到同样的问题。
2016-01-28 13:15:55.683 Google Maps SDK for iOS version: 1.11.21919.0
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address "myIPAddress", with empty referer",
"results" : [
],
"status" : "REQUEST_DENIED",
"html_attributions" : [
]
}
func downloadRestaurantDetails(completed: DownloadComplete) {
let URL_Search = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
let API_iOSKey = "My iOS API Key"
let urlString = "\(URL_Search)location=\(clLatitude),\(clLongitude)&radius=\(searchRadius)&types=\(searchType)&key=\(API_iOSKey)"
let url = NSURL(string: urlString)!
Alamofire.request(.GET,url).responseJSON { (response) -> Void in
if let value = response.result.value {
let json = JSON(value)
print(json)
if let results = json["results"].array {
for result in results {
if let placeIDs = result["place_id"].string {
self.placeIDArray.append(placeIDs)
}
}
}
}
completed()
}
}
这个错误听起来像是您生成了浏览器密钥而不是 iOS 密钥。尝试在 Cloud Console 中生成 iOS 密钥,并确保您的捆绑包 ID 已列入白名单。
您的 API 密钥配置错误。
首先,您的问题是 Google Places API Web Service, which can only be used with Server keys 而不是 iOS 键。您正在调用 Web 服务 (https://maps.googleapis.com/maps/place/...
),因此 iOS 密钥和 bundleID 密钥限制在这里不起作用(并且可能会造成混淆)。
因此您需要按照 https://developers.google.com/places/web-service/get-api-key 中的说明进行操作,并在 Developers Console 中创建一个启用了 "Google Places API Web Service" 的服务器密钥(与 "Google Places API for iOS" 不同)。为了在电话上有用,您可能不想设置任何 IP 限制(IP 限制是服务器密钥唯一可能的类型)。在您的 HTTP 请求中使用该密钥。
任何其他内容都会出现 REQUEST_DENIED 错误。
我在 google 地图 sdk 和地点 api 上工作得很好。昨天我的代码 运行 非常好。但今天早上醒来,做了一些修改,然后 运行 变成了一个滚雪球般的问题,这看起来很容易解决,但花了几个小时试图弄清楚发生了什么。我正在尝试开发一个 iPhone 应用程序。
我回去了,在开发者控制台创建了一个"new project" 重新生成了一个新的 iOS 密钥。 在 info.plist 中输入了新的包 ID 在委托文件和 url.
的搜索参数中输入新的 api 键我正在使用 alamofire 和 swiftyjson 来解析数据
但仍然遇到同样的问题。
2016-01-28 13:15:55.683 Google Maps SDK for iOS version: 1.11.21919.0
{ "error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address "myIPAddress", with empty referer", "results" : [
], "status" : "REQUEST_DENIED", "html_attributions" : [
] }
func downloadRestaurantDetails(completed: DownloadComplete) {
let URL_Search = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
let API_iOSKey = "My iOS API Key"
let urlString = "\(URL_Search)location=\(clLatitude),\(clLongitude)&radius=\(searchRadius)&types=\(searchType)&key=\(API_iOSKey)"
let url = NSURL(string: urlString)!
Alamofire.request(.GET,url).responseJSON { (response) -> Void in
if let value = response.result.value {
let json = JSON(value)
print(json)
if let results = json["results"].array {
for result in results {
if let placeIDs = result["place_id"].string {
self.placeIDArray.append(placeIDs)
}
}
}
}
completed()
}
}
这个错误听起来像是您生成了浏览器密钥而不是 iOS 密钥。尝试在 Cloud Console 中生成 iOS 密钥,并确保您的捆绑包 ID 已列入白名单。
您的 API 密钥配置错误。
首先,您的问题是 Google Places API Web Service, which can only be used with Server keys 而不是 iOS 键。您正在调用 Web 服务 (https://maps.googleapis.com/maps/place/...
),因此 iOS 密钥和 bundleID 密钥限制在这里不起作用(并且可能会造成混淆)。
因此您需要按照 https://developers.google.com/places/web-service/get-api-key 中的说明进行操作,并在 Developers Console 中创建一个启用了 "Google Places API Web Service" 的服务器密钥(与 "Google Places API for iOS" 不同)。为了在电话上有用,您可能不想设置任何 IP 限制(IP 限制是服务器密钥唯一可能的类型)。在您的 HTTP 请求中使用该密钥。
任何其他内容都会出现 REQUEST_DENIED 错误。