1
我注册了Mapquest API服务,现在我正在使用PHP测试我的应用程序。Mapquest API密钥不被识别
在管理密钥,我创建了一个新的密钥,Mapquest服务递给我:
消费重点 消费者揭秘
我点击批准所有按键
我抬头的文档地址解析API Post Batch,它说我应该把密钥作为params之一。
我认为这是消费者密钥,所以我包括我的。但是,当我拨打电话时,我收到以下回复:
与此请求一起提交的AppKey无效。
我的代码:
$results = mapquest_v1_geocoding_batch_get_location(array('123 Main St, Anytown, WA', '123 Main St, Anytown, WA 98052'));
pretty_print($results);
function mapquest_v1_geocoding_batch_get_location($locations)
{
//&location=Denver, CO&location=1555 Blake St, Denver, CO 80202&location=Boulder&key=KEY
$postfields = array (
'inFormat' => 'kvp',
'outFormat' => 'json',
'thumbMaps' => FALSE,
'maxResults' => 1
);
$postfields_string = http_build_query($postfields);
foreach ($locations as $location) {
$postfields_string .= '&'.http_build_query(array('location' => $location));
}
$postfields_string .= '&'.http_build_query(array('key' => PARN_MAPQUEST_TW_TO_FB_KEY));
pretty_echo($postfields_string);
$url = 'https://www.mapquestapi.com/geocoding/v1/batch';
return jhm_curl_post_call($url, $postfields);
}
function jhm_curl_post_call($url, $postfields, $setopts_array = FALSE)
{
$results = array();
if (!$setopts_array) {
$setopts_array = array();
}
if (!isset($setopts_array[CURLOPT_RETURNTRANSFER])) {
$setopts_array[CURLOPT_RETURNTRANSFER] = TRUE;
}
if (!isset($setopts_array[CURLOPT_POST])) {
$setopts_array[CURLOPT_POST] = TRUE;
}
$setopts_array[CURLOPT_URL] = $url;
$setopts_array[CURLOPT_POSTFIELDS] = http_build_query($postfields);
$ch = curl_init();
curl_setopt_array ($ch , $setopts_array);
$results['json_response'] = curl_exec($ch);
$results['response'] = json_decode($results['json_response'], TRUE);
$results['info'] = curl_getinfo($ch);
$results['curl_errno'] = curl_errno($ch);
$results['curl_error'] = curl_error($ch);
curl_close($ch);
return $results;
}
这是$ postfields_string:
inFormat=kvp&outFormat=json&thumbMaps=0&maxResults=1&location=123+Main+St%2C+Anytown%2C+WA&location=123+Main+St%2C+Anytown%2C+WA+98052&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
和调用的结果:
Array
(
[json_response] => The AppKey submitted with this request is invalid.
[info] => Array
(
[url] => https://www.mapquestapi.com/geocoding/v1/batch
[content_type] => text/plain
[http_code] => 403
[header_size] => 236
[request_size] => 198
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.265
[namelookup_time] => 0.062
[connect_time] => 0.109
[pretransfer_time] => 0.203
[size_upload] => 52
[size_download] => 50
[speed_download] => 188
[speed_upload] => 196
[download_content_length] => 50
[upload_content_length] => 52
[starttransfer_time] => 0.265
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 207.200.103.5
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 192.168.1.4
[local_port] => 50514
)
[curl_errno] => 0
[curl_error] =>
)
这没有任何意义。 API端点不包含密钥 – EastsideDeveloper
帖子网址包含密钥(http://www.mapquestapi.com/geocoding/v1/batch?key=KEY),帖子正文包含要进行地理编码的地址({ “location”:[{“city”:“Denver”,“state”:“CO”},{“city”:“Boulder”,“state”:“CO”}],“options”:{“maxResults” :-1,“thumbMaps”:true,“ignoreLatLngInput”:false}} )。有关批次地理编码帖子用户指南页面的更多信息。 https://developer.mapquest.com/documentation/geocoding-api/batch/post/ – MQBrian