我已经完成了获取访问令牌的步骤(我通过使用java的终端这样做了)
当我尝试在终端中使用带有这样的Java的GET请求时:
java -jar rest-oauth-client-1.0.one-jar.jar request ACCESS_TOKEN http://locahost:8015/rest/api/2/issue/TP-113
它起作用并返回一个问题JSON
但是当我尝试使用PHP和cURL这样
$FieldSummary = substr($items[0]->summary,strpos($items[0]->summary,'- ')+2);
$FieldDescription = substr($items[0]->description,0);
$FieldStartTime = new DateTime($items[0]->start->dateTime);
$FieldEndTime = new DateTime($items[0]->end->dateTime);
$dateStart = $FieldStartTime->format("Y-m-d\Th:m:s.sOZ");
$dateEnd = $FieldEndTime->format("Y-m-d\Th:m:s.sOZ");
$url = "http://".$config['jiraAdress']."/rest/api/2/issue/".$FieldKey;
$ch = curl_init($url);
$headers = array(
'Authorization: Bearer ACCESS_TOKEN',
'Accept: application/json',
'Content-Type: application/json'
);
$data = json_encode ( array (
'fields' => array (
'summary' => $FieldSummary,
'description' => $FieldDescription,
'customfield_10007' => $dateStart,
'customfield_10008' => $dateEnd
)
), JSON_PRETTY_PRINT );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
它返回错误401和错误JSON:
{
"errorMessages": [
"You do not have the permission to see the specified issue.",
"Login Required"
],
"errors": {
}
}
我做错了什么?请记住,这是JIRA REST API。