微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

laravel php curl请求finerworks api

如何解决laravel php curl请求finerworks api

我想使用Finerworks API 我的卷曲代码在这里

$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 ) ) ) 

请帮助我解决此问题 预先感谢

解决方法

在标题中传递凭据

$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));
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。