2016-12-27 1 views
0

api.ssactivewear.comを使用すると、PHPコードのオプションは表示されません(例:https://api.ssactivewear.com/V2/Help_Examples.aspx)。どんな助けやサポートも私の問題を解決するかもしれません。phpでapi.ssactivewear.comを使用して製品データを取得するには?

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); 
私が言及した結果の下になった

:私はXMLでデータを取得するためにPHPで言及コードの下に行っている - 文字列(68)

"{ "message": "Authorization has been denied for this request." }"

答えて

0

ソリューションを持って、それが私の作品:

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

解決策を見つける必要があります。 以下のコードはすべて私のために働いています。

$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); 
関連する問題