他们的 API:http ://www.sitescout.com/support/api/#authentication 声明我应该向https://api.sitescout.com/oauth/token提交一个 POST 请求,并将 Authorization 标头设置为我自己的凭据( base64_encode(“用户名:密码”))。下面是一个示例请求:
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);
不管用。有人可以指出我正确的方向吗?多谢。