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

How to access Response Body of GuzzleHttp and Extract Data of Response?

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

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

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

我已经用这个方法解决了,

$array = $response->getBody()->getContents();
$json = json_decode($array, true);
$collection = collect($json);
$access = $collection->get('access_token');