如何获取响应结果的具体值
How to get a specific value of response result
我正在尝试通过 Laravel 控制器使用 Laravel 将图像上传到 Imgur,但是,我已经创建了上传,但我不知道如何获取具体的响应结果的id。谢谢。
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.imgur.com/3/image', [
'headers' => [
'authorization' => 'Client-ID ' . 'my_id',
'content-type' => 'application/x-www-form-urlencoded',
],
'form_params' => [
'image' => base64_encode(file_get_contents($request->file('image')->path()))
],
]);
echo $result = response()->json(json_decode(($response->getBody()->getContents())));
->
可用于访问对象属性。查看以下示例:
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.imgur.com/3/image', [
'headers' => [
'authorization' => 'Client-ID ' . 'my_id',
'content-type' => 'application/x-www-form-urlencoded',
],
'form_params' => [
'image' => base64_encode(file_get_contents($request->file('image')->path()))
],
]);
$response = json_decode($response->getBody()->getContents()));
// get the results:
$id = $response->data->id;
$height = $response->data->height;
我正在尝试通过 Laravel 控制器使用 Laravel 将图像上传到 Imgur,但是,我已经创建了上传,但我不知道如何获取具体的响应结果的id。谢谢。
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.imgur.com/3/image', [
'headers' => [
'authorization' => 'Client-ID ' . 'my_id',
'content-type' => 'application/x-www-form-urlencoded',
],
'form_params' => [
'image' => base64_encode(file_get_contents($request->file('image')->path()))
],
]);
echo $result = response()->json(json_decode(($response->getBody()->getContents())));
->
可用于访问对象属性。查看以下示例:
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.imgur.com/3/image', [
'headers' => [
'authorization' => 'Client-ID ' . 'my_id',
'content-type' => 'application/x-www-form-urlencoded',
],
'form_params' => [
'image' => base64_encode(file_get_contents($request->file('image')->path()))
],
]);
$response = json_decode($response->getBody()->getContents()));
// get the results:
$id = $response->data->id;
$height = $response->data->height;