猿问

如何获取响应结果的特定值

我正在尝试通过 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())));

回首忆惘然
浏览 222回答 1
1回答

蝴蝶不菲

->可用于访问对象属性。查看以下示例:$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;
随时随地看视频慕课网APP
我要回答