如何访问GuzzleHttp的响应主体并提取响应数据?

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

我正在使用Guzzle和Laravel 5.4创建应用程序。在那里我正在请求外部API,它给出这样的响应。

{
  "scope": "PRODUCTION",
  "token_type": "bearer",
  "expires_in": 3600,
  "refresh_token": "",
  "access_token": ""
}

我需要访问此响应的access_token属性。我如何在GuzzleHttp中访问这些内容。响应内容类型在application/json

php laravel-5 response guzzlehttp
1个回答
0
投票

我用这种方法解决了

$array = $response->getBody()->getContents();
$json = json_decode($array, true);
$collection = collect($json);
$access = $collection->get('access_token');
© www.soinside.com 2019 - 2024. All rights reserved.