0

我们将 postmates API 用于杂货应用程序。我们正在使用他们的测试凭证,但我不知道如何使用它。请指导我如何进行基本的 API 调用。我正在使用 PHP。并且想知道哪个是正确的 API 密钥来传递标头。预先感谢!

<?php

$curl = curl_init();
$username = "1f37d2fb-****-4689-****-****57e****"; // sandbox key from postmates developer account
$password = ""; // left this blank, as per the doc

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.postmates.com/v1/customers/my-customer-key/delivery_quotes',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('pickup_address' => '76 9th Ave, New York, NY','dropoff_address' => '76 9th Ave, New York, NY'),
  CURLOPT_HTTPHEADER => array(
    'Authorization: Basic Y2YyZjJkNmQtYTMxNC00NGE4LWI2MDAtNTA1M2MwYWYzMTY1Og==' // Got this from postmates documentation
  ),
));
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");

$response = curl_exec($curl);

curl_close($curl);
echo $response;
?>

当我在邮递员中运行这个 PHP 时,我得到了这个错误:

{
    "kind": "error",
    "code": "forbidden",
    "message": "ForbiddenError"
}

请指导我如何使用 postmates api。谢谢

4

0 回答 0