如何在php中使用api.ssactivewear.com获取产品数据?
How to get product data using api.ssactivewear.com in php?
通过使用api.ssactivewear.com,示例(https://api.ssactivewear.com/V2/Help_Examples.aspx)中的php代码没有选项。任何帮助或支持都可以解决我的问题。我在 php 中完成了下面提到的代码以获取 xml 中的数据:
ini_set("allow_url_fopen", 1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://api.ssactivewear.com/v2/products/B00760003?username=xxxxx&api_key=xxxxxxxxxxxxxxxxxx');
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
我得到以下提到的结果:-
字符串(68)
"{ "message": "Authorization has been denied for this request." }"
找到了解决方案并且对我有用:
$username = "xxxxx";
$password = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
$remote_url = 'https://api.ssactivewear.com/v2/categories/';
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$json = file_get_contents($remote_url, false, $context);
$json=str_replace('},
]',"}
]",$json);
$data = json_decode($json, true);
var_dump($data);
我得想办法了。
以下所有代码都对我有用。
$apiPath = "https://api.ssactivewear.com/v2/products";
$username = 'XXXXXXXX';
$password = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$apiPath);
$headers = array(
'Content-Type:text/html'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
通过使用api.ssactivewear.com,示例(https://api.ssactivewear.com/V2/Help_Examples.aspx)中的php代码没有选项。任何帮助或支持都可以解决我的问题。我在 php 中完成了下面提到的代码以获取 xml 中的数据:
ini_set("allow_url_fopen", 1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://api.ssactivewear.com/v2/products/B00760003?username=xxxxx&api_key=xxxxxxxxxxxxxxxxxx');
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
我得到以下提到的结果:- 字符串(68)
"{ "message": "Authorization has been denied for this request." }"
找到了解决方案并且对我有用:
$username = "xxxxx";
$password = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
$remote_url = 'https://api.ssactivewear.com/v2/categories/';
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$json = file_get_contents($remote_url, false, $context);
$json=str_replace('},
]',"}
]",$json);
$data = json_decode($json, true);
var_dump($data);
我得想办法了。 以下所有代码都对我有用。
$apiPath = "https://api.ssactivewear.com/v2/products";
$username = 'XXXXXXXX';
$password = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$apiPath);
$headers = array(
'Content-Type:text/html'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);