简体   繁体   中英

How to get a specific value of response result

I'm trying to make an image upload to Imgur with Laravel through a Laravel controller, however, I have already created the upload but I don't know how to get the specific Id of the response results. Thank you.

$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())));

我想获得的价值

-> can be used to access object properties. Checkout the following example:

$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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM