他們的API:http://www.sitescout.com/support/api/#authentication 指出我應該提交POST請求到https://api.sitescout.com/oauth/token,授權標頭設置爲我自己的憑據(base64_encode(「username:password」))。下面是一個例子請求: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
似乎提供的訪問令牌提取的信息不正確,您是如何獲取Access令牌的? – lokeshpahal
我使用你的代碼:「https://github.com/lokeshpahal/sitescout".I只需在創建對象時傳遞我的憑據,如下所示:」$ api = new API('CLIENT_ID','CLIENT_SECRET' );」還有什麼我必須設置? – s4suryapal