他们的API:http://www.sitescout.com/support/api/#authentication 声明我应该向https://api.sitescout.com/oauth/token提交POST请求,并将Authorization标头设置为我自己的凭据(base64_encode(“username:password”))。以下是一个示例请求:
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 :(得分:1)
Auth标题应该像:
$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和fatch API报告信息。 它包括用于播放广告系列,网站,广告等的所有功能。
答案 1 :(得分:0)
不确定您遇到了哪些错误,但我认为根据您的示例代码,标头参数中肯定存在问题。 “POST https://api.sitescout.com/oauth/token HTTP / 1.1”不应该是HTTP标头的一部分。
答案 2 :(得分:0)
Digifuse,你能让它发挥作用吗?
如果没有,我相信问题应该在这一部分:
'grant_type' => 'credentials'
实际应该是:
'grant_type' => 'client_credentials'