最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to get data from Guzzle and API response in Laravel - Stack Overflow

programmeradmin6浏览0评论

I am new to working with an API. I am using guzzle and Laravel. How to I output specific data such as just the actor's name and image?


    $client = new \GuzzleHttp\Client();

    //$client = new GuzzleHttpClient();

    $response = $client->request('GET', '', [
    'headers' => [
        'x-rapidapi-host' => 'imdb232.p.rapidapi',
        'x-rapidapi-key' => 'xxxxxx',
    ],
]);

    echo $response->getBody();

  {"data":{"name":{"__typename":"Name","id":"nm0000573","nameText":{"text":"Dolly Parton"}

Here is the data for the image.

"primaryImage":{"__typename":"Image","id":"rm2099682048","url":".V1.jpg",

I am new to working with an API. I am using guzzle and Laravel. How to I output specific data such as just the actor's name and image?


    $client = new \GuzzleHttp\Client();

    //$client = new GuzzleHttpClient();

    $response = $client->request('GET', 'https://imdb232.p.rapidapi/api/actors/get-bio?nm=nm0000573', [
    'headers' => [
        'x-rapidapi-host' => 'imdb232.p.rapidapi',
        'x-rapidapi-key' => 'xxxxxx',
    ],
]);

    echo $response->getBody();

  {"data":{"name":{"__typename":"Name","id":"nm0000573","nameText":{"text":"Dolly Parton"}

Here is the data for the image.

"primaryImage":{"__typename":"Image","id":"rm2099682048","url":"https://m.media-amazon/images/M/MV5BMTQxNjI5MjI2NV5BMl5BanBnXkFtZTYwMzExMzI1.V1.jpg",

Share Improve this question edited Mar 27 at 18:56 Bloke asked Mar 24 at 17:47 BlokeBloke 176 bronze badges 4
  • 2 Did you try json_decode? php/manual/en/function.json-decode.php Should be able to do $obj = json_decode($response->getBody());, then $obj->data->name->nameText would output 'Dolly Parton'. That should point you in the right direction
发布评论

评论列表(0)

  1. 暂无评论