我正在创建一个网站。在此网站上,我使用API来获取数据。但是,我想创建一个访问令牌以在API中使用。然后,我使用下面的代码生成访问代码。但是,它总是给我这个错误-
“ {” error_description“:”客户端身份验证失败。“,” error“:” invalid_client“}”
如何通过解决此错误来生成访问令牌?
这里是控制器。 (AccessToken.php)
public function Authenticate(){
$id = "jhsdhfvbsdhdg";
$secret = "sgfgfhfdnn";
$tokengen = "Base64($id:$secret)";
$url = 'http://api.gate.com:8254/token';
$tokengenheaders = array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'Authorization: Basic '.$tokengen
);
$data = array('client_id'=>'jhsdhfvbsdhdg',
'client_secret'=>'sgfgfhfdnn',
'grant_type'=>'client_credentials');
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch2, CURLOPT_HTTPHEADER, $tokengenheaders);
curl_setopt($ch2, CURLOPT_POST, true);
//curl_setopt($ch2, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch2, CURLOPT_POSTFIELDS, "grant_type=client_credentials&client_id=$id&client_secret=>$secret");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$tokenid = curl_exec($ch2);
curl_close($ch2);
dd($tokenid); die();
// return $tokenid;
}