API 未获取访问令牌
The API isnt getting access token
这是我的 curl 中出现的错误 PHP
HTTP/1.1 401 Unauthorized Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/10.0 X-AspNet-Version: 4.0.30319 WWW-Authenticate: Bearer WWW-Authenticate: Bearer X-Powered-By: ASP.NET Date: Thu, 23 Apr 2020 10:57:54 GMT Content-Length: 61 {"Message":"Authorization has been denied for this request."}";
API 没有收到访问令牌,我认为它缺少授权。请帮助我使用下面的授权代码正确添加我的代码,我有点困惑在哪里添加它。
下面是授权码
curl_setopt($handle1, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token));
//我写的代码
<?php
$access_token = $_SESSION['token'];
$request_headers = array();
$request_headers[] = 'Bearer: ' . $access_token;
//$request_headers[]='Content-Length:150';
$handle1 = curl_init();
$api_url = 'API';
curl_setopt_array(
$handle1,
array(
CURLOPT_URL => $api_url,
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $request_headers,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => -1,
)
);
$data = curl_exec($handle1);
echo serialize($data);
?>
$request_headers[] = 'Bearer: ' . $access_token;
好像打错了 -> $request_headers[] = 'Authorization: Bearer ' . $access_token;
这是我的 curl 中出现的错误 PHP
HTTP/1.1 401 Unauthorized Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/10.0 X-AspNet-Version: 4.0.30319 WWW-Authenticate: Bearer WWW-Authenticate: Bearer X-Powered-By: ASP.NET Date: Thu, 23 Apr 2020 10:57:54 GMT Content-Length: 61 {"Message":"Authorization has been denied for this request."}";
API 没有收到访问令牌,我认为它缺少授权。请帮助我使用下面的授权代码正确添加我的代码,我有点困惑在哪里添加它。
下面是授权码
curl_setopt($handle1, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token));
//我写的代码
<?php
$access_token = $_SESSION['token'];
$request_headers = array();
$request_headers[] = 'Bearer: ' . $access_token;
//$request_headers[]='Content-Length:150';
$handle1 = curl_init();
$api_url = 'API';
curl_setopt_array(
$handle1,
array(
CURLOPT_URL => $api_url,
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $request_headers,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => -1,
)
);
$data = curl_exec($handle1);
echo serialize($data);
?>
$request_headers[] = 'Bearer: ' . $access_token;
好像打错了 -> $request_headers[] = 'Authorization: Bearer ' . $access_token;