Problem with cURL and rest API

1 views
0

I use last version of wordpress and woocommerce but I get this {"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot list resources.","data":{"status":401}} when I try to get product by curl in php. there is my code:

$ch = curl_init("http://localhost/wp-json/wc/v1/products  -u ck_4e2f7166b48212888b1bb1d0a6e54371878abfd1:cs_822687fc36460c6a6d767737c967dfcfdcf2c3db");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
echo $result;
curl_close($ch);

I also use before -u but still I get Error 401. is there any spacial option should I use for CURL in php?