我一直试图在Koha的php中使用REST在头文件中传递生成的令牌,这是我一直得到的;
{"error":"Authentication failure."}
想使用下面的代码从koha获得顾客数据;
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "mykohadomain:8000/api/v1/oauth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=clientID&client_secret=clientSecret",
CURLOPT_HTTPHEADER => [
"content-type: application/x-www-form-urlencoded"
],
]);
$response = json_decode(curl_exec($curl));
$err = curl_error($curl);
curl_close($curl);
$token = $response->access_token;
echo "<pre>";
print_r($response);
echo "</pre>";
$curl2 = curl_init();
curl_setopt_array($curl2, [
CURLOPT_URL => "mykohadomain:8000/api/v1/patrons",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ".$token,
"Content-Type: application/json"
],
]);
$response2 = curl_exec($curl2);
$err2 = curl_error($curl2);
curl_close($curl2);
echo "<pre>";
print_r($response2);
echo "</pre>";
?>
令牌被正确地打印出来了,但是当在第二次调用GET顾客时传递令牌时,我得到了授权失败。任何人都知道如何解决这个问题。
1条答案
按热度按时间k0pti3hp1#
首先确保启用系统首选项REST API选项,然后
php代码