为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
回首忆惘然 2021-12-03 19:47:02
我正在尝试通过 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())));
查看完整描述

1 回答

?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

->可用于访问对象属性。查看以下示例:


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


查看完整回答
反对 回复 2021-12-03
  • 1 回答
  • 0 关注
  • 221 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号