进程休息响应php

问题描述 投票:0回答:1

我正在调用一个站点来获取访问令牌。这是响应如何使用php获取实际令牌。

HTTP/1.1 200 OK Date: Sat, 16 Dec 2017 16:54:20 GMT
Content-Type: application/json;
charset=UTF-8
Content-Length: 113
Connection: keep-alive
Cache-Control: no-store
Server: Apigee Router { "access_token": "1NQA27eHVzHC6idx2f7JDbJiD4CQ", "expires_in": "3599" }

以下代码失败。

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Basic '.$credentials)); //setting a custom header
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$curl_response = curl_exec($curl);
$token = $curl_response['access_token'];
echo "<br/>";
echo $token;
php rest token access
1个回答
0
投票

您需要在访问值之前解码JSON。

$curl_response = curl_exec($curl);
curl_close ($curl);
$data = json_decode($curl_response,true); 
$token = $data['access_token'];
echo "<br/>";
echo $token;
© www.soinside.com 2019 - 2024. All rights reserved.