dotelauv682684 2017-05-28 11:55
浏览 87
已采纳

使用Laravel 5.4显示JSON数组结果

I have a JSON array result downloaded from Instagram. I need the image URL to show the posts from Instagram. How I can retrieve all image URLs?

"pagination": {},
"data": [
{
  "id": "1501575131271622723_414010731",
  "user": {
    "id": "414010731",
    "full_name": "Amir_P",
    "profile_picture": "https://ig-s-b-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-19/s150x150/12976101_1022789394464141_915552926_a.jpg",
    "username": "amir_p__"
  },
  "images": {
    "thumbnail": {
      "width": 150,
      "height": 150,
      "url": "https://scontent.cdninstagram.com/t51.2885-15/s150x150/e35/c100.0.880.880/18096357_1952671591631445_7945040983308107776_n.jpg"
       },

"images": {
    "thumbnail": {
      "width": 150,
      "height": 150,
      "url": "https://scontent.cdninstagram.com/t51.2885-15/s150x150/e35/c0.135.1080.1080/17268108_1309342792475888_7209542398102208512_n.jpg"
    },
  • 写回答

1条回答 默认 最新

  • duanbicheng3345 2017-05-28 13:13
    关注

    I find this way That worked for me.

    public function picture(Request $request)
    {
        if ($request->session()->has("access_token")) {
            $access_token = $request->session()->get("access_token");
            $client = new Client();
            $res = $client->request('GET', 'https://api.instagram.com/v1/users/self/media/recent/?access_token=' . $access_token);
            if ($res->getBody()) {
                $body = $res->getBody();
                $obj = \GuzzleHttp\json_decode($body);
                $data = $obj->data;
                foreach ($data as $img) {
                    $img = $img->images->thumbnail->url;
                    //echo "
    ";
                }
                           }
    
        } else {
            echo "there is no access token in session";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?