해당 API : http://www.sitescout.com/support/api/#authentication 은 인증 요청 헤더를 내 자격 증명 (base64_encode ("username : password"))으로 설정하여 https://api.sitescout.com/oauth/token에게 POST 요청을 제출해야한다고 나와 있습니다.SiteScout oauth2 인증
POST https://api.sitescout.com/oauth/token HTTP/1.1
Host: api.sitescout.com
Authorization: Basic YmVldGhvdmVuOmxldG1laW4=
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Content-Length: 41
grant_type=client_credentials&scope=STATS
나는 이런 식으로 뭔가를 받고되어야한다 :
{
"scope": "STATS",
"access_token": "7ebe55b54ee12a8ee07329f1cefd6de6",
"token_type": "bearer",
"expires_in": 3600
}
내 코드 :
$url = "https://api.sitescout.com/oauth/token";
$ch = curl_init();
$headers = array(
"POST https://api.sitescout.com/oauth/token HTTP/1.1",
"HOST: api.sitescout.com",
"Authorization: Basic ZGlnaWZ1c2UtYXBpOnh1M2pkODll****",
"Content-Type: application/x-www-form-urlencoded",
"Accept: application/json",
"Content-Length: 41"
);
$post_fields = array(
'grant_type' => 'credentials'
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
//$info = curl_getinfo($ch);
curl_close($ch);
var_dump($output);
가 작동하지 않는 아래의 예 요청입니다. 누군가가 올바른 방향으로 나를 가리킬 수 있었습니까? 고마워.
"제공 잘못된 액세스 토큰을"포함 당신이 나를 도와 드릴까요? – s4suryapal
정보가 올바르지 않은 경우 액세스 토큰이 제공되는 것 같습니다. 어떻게 액세스 토큰을 가져 왔습니까? – lokeshpahal
나는 "https://github.com/lokeshpahal/sitescout"에서 귀하의 코드를 사용했습니다. 다음과 같이 객체를 생성 할 때 내 자격 증명을 전달하기 만하면됩니다. "$ api = new API ('CLIENT_ID', 'CLIENT_SECRET'); " 내가 정해야 할게있어? – s4suryapal