Skip to content

arifurrahmansw/Add-Instagram-feed-to-a-Laravel-site-without-any-package

Repository files navigation

Insatgram Feed

Step: 1

Create laravel project


    composer create-project --prefer-dist laravel/laravel instagram_feed

Step: 2

Create Instagram access token from this link

Step: 3

Add access token in .env file

   
    INSTAGRAM_ACCESS_TOKEN=""

Step: 4

Make controller InstagramFeedController


    namespace App\Http\Controllers;
use Illuminate\Http\Request;

class InstagramFeedController extends Controller
{


    public function getInstagram(){
            $data                   = [];
        $limit                  = 4;
        $token                  = env('INSTAGRAM_ACCESS_TOKEN');
        $fields                 = "id,media_type,media_url,thumbnail_url,timestamp,permalink,caption";
        $instafeeds             = $this->getInstagramPost($fields,$token,$limit);
        return view('welcome')->withRows($instafeeds);
    }

    public function getInstagramPost($fields,$token,$limit){
            $url = "https://graph.instagram.com/me/media?fields=".$fields.'&access_token='.$token.'&limit='.$limit;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 20);
            $result = curl_exec($ch);
            curl_close($ch);
            $result_decode = json_decode($result, true);
            return $result_decode;
    }



}

Step: 5

   
        @if(!empty($rows))
        @foreach($rows as $row)
        
    @endforeach
    @endif

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages