2013-10-24 2 views
1

해당 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); 

가 작동하지 않는 아래의 예 요청입니다. 누군가가 올바른 방향으로 나를 가리킬 수 있었습니까? 고마워.

답변

0

내가 만난 오류가 확실하지 않지만 샘플 코드를 기반으로 헤더 매개 변수에 잘못된 것이 있어야한다고 생각합니다. "POST https://api.sitescout.com/oauth/token HTTP/1.1"은 HTTP 헤더의 일부가 아니어야합니다.

0

Digifuse, 작동시킬 수 있었습니까?

'grant_type' => 'credentials' 

실제로해야하는 :

하지 않으면, 나는 문제가이 부분에 있어야한다고 생각

'grant_type' => 'client_credentials' 
1

인증 헤더 좋아한다 :

$header = array(
     "POST https://api.sitescout.com/oauth/token HTTP/1.1", 
     "HOST: api.sitescout.com", 
     "Authorization: {$this->_auth_header}", 
     "Content-Type: application/x-www-form-urlencoded", 
     "Accept: application/json", 
     "Content-Length: 41" 
    ); 

당신이 할 수있는 또한이 API 래퍼 클래스를 사용하여 Auth를 만들고 API보고 정보를 패치합니다. 그것은 .. 모든 기능 캠페인, 사이트, 광고 문안 등을 fatch하는

내가 오류를 얻고있다

https://github.com/lokeshpahal/sitescout

+0

"제공 잘못된 액세스 토큰을"포함 당신이 나를 도와 드릴까요? – s4suryapal

+0

정보가 올바르지 않은 경우 액세스 토큰이 제공되는 것 같습니다. 어떻게 액세스 토큰을 가져 왔습니까? – lokeshpahal

+0

나는 "https://github.com/lokeshpahal/sitescout"에서 귀하의 코드를 사용했습니다. 다음과 같이 객체를 생성 할 때 내 자격 증명을 전달하기 만하면됩니다. "$ api = new API ('CLIENT_ID', 'CLIENT_SECRET'); " 내가 정해야 할게있어? – s4suryapal