laravel php 对 finerworks 的 curl 请求 api
laravel php curl request for finerworks api
我想使用 finerworks api
我的 curl 代码在这里
$data1 = array(
'web_api_key' => '********-****-****-*****-************',
'app_key' => '********-****-****-*****-************',
);
$data2['credentials'] = $data1;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.finerworks.com/v3/test_my_credentials",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data2),
CURLOPT_HTTPHEADER => array(
"accept: */*",
"accept-language: en-US,en;q=0.8",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
print_r(json_decode($response));
}
当我 运行 这里的代码是我下面的请求响应
stdClass Object ( [Message] => The request is invalid. [ModelState] => stdClass Object ( [ApiC.Models.authorization_credentials] => Array ( [0] => Missing or unauthorized api credentials ) ) )
请帮我解决这个问题
提前致谢
传递 header
中的凭据
$data1 = array(
'web_api_key' => '********-****-****-*****-************',
'app_key' => '********-****-****-*****-************',
);
$data2['credentials'] = $data1;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.finerworks.com/v3/test_my_credentials",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data2),
CURLOPT_HTTPHEADER => array(
"accept: */*",
"accept-language: en-US,en;q=0.8",
"content-type: application/json",
"web_api_key: YOUR web_api_key",
"app_key: YOUR app_key",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:".$err;
} else {
print_r(json_decode($response));
}
我想使用 finerworks api 我的 curl 代码在这里
$data1 = array(
'web_api_key' => '********-****-****-*****-************',
'app_key' => '********-****-****-*****-************',
);
$data2['credentials'] = $data1;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.finerworks.com/v3/test_my_credentials",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data2),
CURLOPT_HTTPHEADER => array(
"accept: */*",
"accept-language: en-US,en;q=0.8",
"content-type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
print_r(json_decode($response));
}
当我 运行 这里的代码是我下面的请求响应
stdClass Object ( [Message] => The request is invalid. [ModelState] => stdClass Object ( [ApiC.Models.authorization_credentials] => Array ( [0] => Missing or unauthorized api credentials ) ) )
请帮我解决这个问题 提前致谢
传递 header
中的凭据$data1 = array(
'web_api_key' => '********-****-****-*****-************',
'app_key' => '********-****-****-*****-************',
);
$data2['credentials'] = $data1;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.finerworks.com/v3/test_my_credentials",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data2),
CURLOPT_HTTPHEADER => array(
"accept: */*",
"accept-language: en-US,en;q=0.8",
"content-type: application/json",
"web_api_key: YOUR web_api_key",
"app_key: YOUR app_key",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:".$err;
} else {
print_r(json_decode($response));
}