HTTP 기본 인증을 사용하여 API에서 데이터를 가져 오려고합니다. API에 대한 HTTP 요청은 HTTP 기본 인증으로 보호됩니다. HTTP 기본 인증은 토큰과 비밀로 구성됩니다.HTTP 기본 인증 cURL (PHP 사용)
여러 가지 기술을 시도했지만 인증이 제공되지 않았다는 응답을 계속받습니다. token : secret 메소드가 username : password와 다른지 확실하지 않지만 인증을받을 수 없습니다.
stdClass는 ( [ERROR_MESSAGE] => 인증이 제공되지 .) 객체
다음는 API 문서입니다 - https://www.whatconverts.com/api/
<?php
$token = "xxx";
$secret = "yyy";
$response = get_web_page("https://leads.seekmomentum.com/api/v1/leads");
$resArr = array();
$resArr = json_decode($response);
echo "<pre>"; print_r($resArr); echo "</pre>";
function get_web_page($url) {
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_HTTPAUTH => "CURLAUTH_BASIC", // authentication method
CURLOPT_USERPWD => "$token:$secret", // authentication
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
?>
별도의 CURLOPT_USERNAME과 CURLOPT_PASSWORD를 사용해 보셨습니까? –
자격증을 가져 주셔서 감사합니다 ... 즉시 변경/무효화 된 것을 가져오고 싶을 수도 있습니다. –
'CURLAUTH_BASIC' 주변의 따옴표를 제거하십시오. 이것은 값이 아닌 상수입니다. – iainn