我最近找到了一份新工作。他们需要我通过使用PHP的API从ShipStation获取信息。我是PHP的新手,甚至是ShipStation的新手。我复制了API文档中的代码,并尝试添加授权代码。这就是我得到的:
<?php
$apiKey = "my_api_key";
$apiSecret = "my_api_secret";
$auth = base64_encode($apiKey . ":" . $apiSecret);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ssapi.shipstation.com/orders");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Basic " . $auth
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>
它返回的不是订单信息,而是bool(false)
。
我想我只是看不出我做错了什么。任何帮助都将不胜感激。谢谢!
发布于 2020-12-09 16:17:46
这是在搜索"Shipstation API PHP“时出现的,所以我想指出这个答案How do I make a request using HTTP basic authentication with PHP curl?,并重申这是一个基本的身份验证,所以你只需要这样做
curl_setopt($ch, CURLOPT_USERPWD, $apiKey . ":" . $apiSecret);
我还建议通过安全连接发送它,以避免中间人读取您的API凭据。
发布于 2021-05-14 18:05:29
我通过以下方式与CURL连接:
$url = 'https://ssapi.shipstation.com/orders';
$ShpStnAuth = 'Authorization: basic '.base64_encode('key:pair');
$curl = curl_init();
curl_setopt_array(
$curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Host: ssapi.shipstation.com',
$this->ShpStnAuth,
),
)
);
$response = curl_exec($curl);
curl_close($curl);
print_r($response);
https://stackoverflow.com/questions/59402448
复制相似问题