Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 需要连接到ShipStation API的帮助吗_Php_Curl - Fatal编程技术网

Php 需要连接到ShipStation API的帮助吗

Php 需要连接到ShipStation API的帮助吗,php,curl,Php,Curl,我最近找到了一份新工作。他们需要我使用PHP通过API从ShipStation获取信息。我对PHP相当陌生,对ShipStation甚至更新。我从API文档中复制了代码,并尝试添加代码以进行授权。这就是我得到的: <?php $apiKey = "my_api_key"; $apiSecret = "my_api_secret"; $auth = base64_encode($apiKey . ":" . $apiSecret); $ch = curl

我最近找到了一份新工作。他们需要我使用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)


我想我只是看不出我做错了什么。任何帮助都将不胜感激。谢谢

这是在搜索“Shipstation API PHP”查询时出现的,所以我想指出这个答案,并重申这是一个基本的身份验证,所以您只需要

curl_setopt($ch,CURLOPT_USERPWD,$apiKey.:“$apiSecret)


<>我也建议通过一个安全的连接来发送,以避免中间的人读取您的API证书。

< p>我以这种方式与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);