我的代码有问题。因此,我已经阅读了许多关于Stackoverflow和eBay API文档的文章。但是我仍然无法正常工作。
我已经尝试过更改'setopt'变量,但是它不起作用。
注意:该代码位于构造函数中。
$headers = [
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode($user_key . ":" . $user_secret),
];
$body = http_build_query([
'grant_type' => 'authorization_code',
'code' => $oauth,
'redirect_uri' => $runame,
]);
switch($action){
case "import-products":
$cmd = "https://api.ebay.com/oauth/api_scope/sell.inventory";
break;
default:
$cmd = "";
break;
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => $headers,
));
$response = curl_exec($curl);
$err = curl_error($curl);
if(curl_errno($curl)){
print curl_error($curl);
}
curl_close($curl);
if($err){
echo "cURL Error: ".$err;
}else{
echo "cURL Successful: ";
var_dump(json_decode($response, true));
echo "\n";
}
结果始终为“ cURL成功:NULL”,但我想以JSON格式而不是NULL来获取整个清单。