簡體   English   中英

Instagram API與Laravel 5.4

[英]Instagram API with Laravel 5.4

我使用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獲取圖像images->standard_resolution->url

我試圖重復雙數組foreach至今沒有運氣。

關於如何實現這一點的任何建議?

使用laravel 集合中的 map將簡單地獲取網址

$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中有一個很好的幫手

   $yourCollection =  collect(yourArray);

那么你可以在Eloquent上應用與Collection相同的查詢,也可以應用foreach循環。

編輯2

你也可以這樣做

 $yourArray = json_decode($getUser,true);

你可以在它上面應用一個循環。

@foreach($yourArray as $arr){
    //do what ever you want to do with
   $arr['standard_resolution']['url'];
  }

我希望這有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM