Laravel 5 Instagram API tutorial with example

LaravelFeed
2 min readNov 28, 2016

--

Today, I am going to show you how to access Instagram Feed using instagram API. We can get our instagram feed without using any composer package, I simply use GuzzleHttp for getting instagram feed, We can also get location, likes, comments, images, name, id and etc.

GuzzleHttp provide use fire get request to given api, So i simply run “https://www.instagram.com/username/media" API like, It is very basic example without generate instagram token. Here you can access feed of any user by username.

This example is very simple and you can get by follow few step, you can also check demo and after run successfully this example, you will find following preview. So let’s follow few step:

Step 1: Create Route

In this step, we require to create one route for manage view layout and get method for getting username. so open your routes/web.php file and add following route.

routes/web.php

Route::get('instagram', 'InstagramController@index');

Step 2: Create Controller

In this point, now we should create new controller call InstagramController in this path app/Http/Controllers/InstagramController.php. In this controller we will manage route method, i added one method in this controller as listed bellow:

1) index()

So, copy bellow code and put in your controller file.

app/Http/Controllers/InstagramController.php

namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; class InstagramController extends Controller { /** * Get the index name for the model. * * @return string */ public function index(Request $request) { $items = []; if($request->has('username')){ $client = new \GuzzleHttp\Client; $url = sprintf('https://www.instagram.com/%s/media', $request->input('username')); $response = $client->get($url); $items = json_decode((string) $response->getBody(), true)['items']; } return view('instagram',compact('items')); } }

Step 3: Create View

Originally published at laravelfeed.com.

--

--