簡體   English   中英

cURL 發布 api 調用並在 Aliseeks api 上進行身份驗證

[英]cURL post api call with authentification on Aliseeks api

我正在嘗試使用 CURL 連接到Aliseeks api 但我不確定將我的 api 密鑰放在哪里。

他們在 API 的文檔上說

"Aliseeks expects for the API key to be included in all API requests in a header that look like the following: X-Api-Client-Id: Your Api Key"

現在我正在這樣做:

$url = 'https://api.aliseeks.com/v1/products/details';
$curl = curl_init();
$auth_data = array(
    "X-Api-Client-Id" => 'my_api_key_here',
);

curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HEADER, $auth_data );
curl_setopt($curl, CURLOPT_POSTFIELDS, $auth_data);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

$result = curl_exec($curl);
if(!$result){die("Connection Failure");}
curl_close($curl);
echo $result;

但在回報中,我得到:

[{"code":"no_token_found","violation":"aliseeks.authentication.notokenfound"}]

任何想法?

ps:$auth_data 在這里兩次,因為我現在正在嘗試所有的東西......

您使用了錯誤的常量來發送標頭。

它應該是CURLOPT_HTTPHEADER而不是CURLOPT_HEADER

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM