编程语言
首页 > 编程语言> > PHP-使用Laravel 5.4的Instagram API

PHP-使用Laravel 5.4的Instagram API

作者:互联网

我正在使用Instagram软件包vinkla将用户数据获取到我的应用程序.

这是我用来获得结果的代码:

public function instagram()
{
   $insta = new Instagram();

   $getUser = $insta->get('gopro');

   dd($getUser);
}

当我死掉结果时,我得到以下数组:

array:20 [▼
  0 => {#205 ▼
    +"id": "1552323772757218591_28902942"
    +"code": "BWK9j8rlpUf"
    +"user": {#208 ▶}
    +"images": {#202 ▼
      +"thumbnail": {#203 ▶}
      +"low_resolution": {#214 ▶}
      +"standard_resolution": {#204 ▼
        +"width": 640
        +"height": 640
        +"url": "https://scontent-frt3-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/19624693_104174916895493_9107740182827761664_n.jpg"
      }
    }
    +"created_time": "1499271435"
    +"caption": {#207 ▶}
    +"likes": {#215 ▶}
    +"comments": {#222 ▶}
    +"can_view_comments": true
    +"can_delete_comments": false
    +"type": "image"
    +"link": "https://www.instagram.com/p/BWK9j8rlpUf/"
    +"location": {#223 ▶}
    +"alt_media_url": null
  }
  1 => {#224 ▶}
  2 => {#251 ▶}
  3 => {#278 ▶}

]

现在,我正在尝试处理的事情:
我想在laravel应用中集成一些图像.基本上,我想从每个数组images-> standard_resolution-> URL中获取图像URL.

到目前为止,我尝试过使用double foreach进行迭代来使数组没有运气.

关于如何实现这一目标的任何建议?

解决方法:

使用来自laravel collection的地图只会获取网址

$data = collect($getUser)->map(function($v) {
    return $v->images->standard_resolution->url;
});

你也可以使用foreach

$urls = [];
foreach ($getUser as $row) {
    array_push($urls, $row->images->standard_resolution->url);
}

dd($urls);

标签:laravel,api,instagram,arrays,php
来源: https://codeday.me/bug/20191111/2018166.html