Instagram Feed in PHP
STE 1 : Get Instagram Access Token
https://docs.oceanwp.org/article/487-how-to-get-instagram-access-token
STEP 2 : PHP Code for Website
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <?php $access_token = 'IGQVJWR0VIbHF6cGl0aTZA5NnFsMkxhbHY3MmR0em83emNZAQ3Vxa0dtenRrTHZAqVzFpbHhENmtDRjNIY2lFSGthUkFzX191TEU3SDJzcVJDcnNTYkVYVFlRa1JJZAE12YmFLMVdpWUV4YTJ6cGxWeDBmaQZDZD'; $fields ='id,caption,thumbnail_url,media_url,permalink'; function fetchData($url){ $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); return $result; } $result = fetchData("https://graph.instagram.com/me/media?fields=".$fields."&access_token=".$access_token.""); $result = json_decode($result); //echo'<pre>'; //print_r($result); die(); foreach ($result->data as $post) { $thumbnail_url = $post->thumbnail_url; $image = $post->media_url; $url = $post->permalink; $caption = $post->caption; // Text content ?> <div style="width:20%; float:left; padding:5px; margin:5px; border:solid 1px #ebebeb;"> <a href="<?php echo $url; ?>" target="_blank"> <?php if($thumbnail_url==""){ ?> <img src="<?php echo $image; ?>" width="100%"> <?php }else{ ?> <img src="<?php echo $thumbnail_url; ?>" width="100%"> <?php } ?> <p><?php echo $caption; ?></p> </a> </div> <?php } ?> |