Bitpanda php curl失败api密钥

5uzkadbs  于 2022-11-13  发布在  PHP
关注(0)|答案(1)|浏览(122)

我正在尝试使用PHP curl连接到Bitpanda网站来检索我的加密资产。
不幸的是,它不工作,我添加了一个Powershell脚本,工程,我希望有人能把它翻译成PHP...
我收到以下错误消息:

{"errors":[{"status":401,"code":"unauthorized","title":"Credentials\/Access token wrong"}]}

下面是来自Bitpanda的例子:

curl -X GET "https://api.bitpanda.com/v1/trades" \
    -H "X-API-KEY: string"

如果解决方案是JavaScript的,那对我来说就足够了:)
先谢谢你
php不工作:

$service_url = "https://api.bitpanda.com/v1/trades";
    $curl_session = curl_init($service_url);

    curl_setopt($curl_session, CURLOPT_USERPWD, $apiKey);
    curl_setopt($curl_session, CURLOPT_HTTPHEADER, ['content-type: application/json']);
    curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($curl_session);
    curl_close($curl_session);
    echo $result;

powershell的工作原理:

$key = "APIKEY"
$trades = Invoke-WebRequest -Uri "https://api.bitpanda.com/v1/trades" -Headers @{"X-API-KEY" = $key} -UseBasicParsing
$tdata = $trades.Content | ConvertFrom-Json
$tdata.data.attributes | Out-GridView
3df52oht

3df52oht1#

试试看:

$header = array('X-API-KEY' => 'string');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.bitpanda.com/v1/trades');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header );

$response = curl_exec($ch);

相关问题