我正在为我的书店使用 postmates API。我正在使用他们的测试凭据,但我不知道如何使用它。请指导我如何进行基本的 api 调用。我正在使用 PHP。我想使用 cURL 发送帖子数据 谢谢
<?php
$url = "https://api.postmates.com/v1/customers/my-customer-key/delivery_quotes";
$uname = "my-api-key";
$pwd = null;
$data = array(
'dropoff_address' => '20 McAllister St, San Francisco, CA 94102',
'pickup_address' => '101 Market St, San Francisco, CA 94105',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$uname:$pwd");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
if (curl_errno($ch)) {
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo $output;
?>