Postmates API 使用 php/curl - 返回未授权/无效的 OAuth 2.0 凭据

时间:2021-07-18 20:41:16

标签: php api curl postmates

我得到了一些 postmates 客户和 api 凭据 (https://partner.postmates.com/welcome-api) 按照这里的例子https://documenter.getpostman.com/view/3967924/RW1Yq1oN#993c52be-abcc-b06b-3f3d-0abfe9782484像这样

$customerId = 'cus_xxxxxxxxxx';
$apiKey = 'aaaaaa-bbbbb-ccc-dddd-eeeeeeee';
$authKey = base64_encode($apiKey.':');
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.postmates.com/v1/customers/'.$customerId.'/delivery_quotes',
  CURLOPT_HEADER => true,
  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' => '46 Maujer St, Brooklyn, NY'),
  CURLOPT_SSL_VERIFYPEER => false,
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/x-www-form-urlencoded',
    'Accept: application/json',
    'Authorization: Basic '.$authKey.'',
  ),
));

$response = curl_exec($curl);
curl_close($curl);

echo $response;
exit();

(当然使用实际的 customerId 和 apiKey) 但我只得到以下结果:

{"code":"unauthorized","message":"Invalid OAuth 2.0 credentials provided."}

(CURLOPT_SSL_VERIFYPEER = false 只是为了简单起见在此处的测试环境中添加,在经过 ssl 验证的实时服务器上使用它会产生相同的结果) 我当然对 customerid 和 api 密钥进行了两次和三次检查,但结果没有改变

如果有人知道我错过了什么,那就太好了,因为我已经用头撞墙好几个小时了

0 个答案:

没有答案