2017-07-03 65 views
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] => 
) 

回答

0

的關鍵需求是在URL參數在mapquestapi.com之後而不是在發佈數據之後。那麼你應該很好去。

+0

這沒有任何意義。 API端點不包含密鑰 – EastsideDeveloper

+0

帖子網址包含密鑰(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