2017-12-18 3 views
0

액세스 토큰을 얻기 위해 사이트를 호출하고있었습니다. 여기에 응답은 어떻게 PHP를 사용하여 실제 토큰을 얻을 수 있습니다.프로세스 나머지 응답 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; 
+0

어떤 오류가 발생합니까? –

+0

https://stackoverflow.com/a/1234556/3548935 –

답변

0

값에 액세스하기 전에 JSON을 디코딩해야합니다.

$curl_response = curl_exec($curl); 
curl_close ($curl); 
$data = json_decode($curl_response,true); 
$token = $data['access_token']; 
echo "<br/>"; 
echo $token;