1

I have to create a custom module (or anything else what let me do what i want to), which will display few latest pictures from my instagram on homepage. I do not know how to use Instagram api to do this, where to put which code. If you have any advice how to do this, it will be nice. It does not have to be very complicated. Just take for example 5 latest pictures and display them in custom block. I know how to create custom module, create block and display it on homepage. I dont know how to take pictures url from my instagram and put them into my module.

Thank you for any help.

  • I will check tomorrow if no body comes up with solution. This is simple. – Sohel Rana Jul 8 '19 at 18:12
  • @SohelRana, thank you very much :) – SebastianT Jul 8 '19 at 18:59
  • @SohelRana is there a chance for your help? :) – SebastianT Jul 9 '19 at 8:54
2

Try following code:

$userId = 1232134;
$accessToken = '';
$url = 'https://api.instagram.com/v1/users/'.$userId.'/media/recent?access_token='.$accessToken.'&count=5';

$args = stream_context_create(array('http' => array('timeout' => 2500,)));

$instagramFeedsData = file_get_contents($url, false, $args);

$data = json_decode($instagramFeedsData);

There are two variables where $userId is instagram user id and $accessToken is you need to create that.

  • thank you for answer, but using your code, i get warning with 'file_get_contents', failed to open stream: HTTP request failed!. i get all informations using 'curl_setopt' function. Could you tell me what is the most appropriate method to implement this code?. Now everything i do in my .phtml file. But i was wondering if this is good practice or should i use some controllers or anything else? – SebastianT Jul 10 '19 at 8:41
  • All php code should under Block class. – Sohel Rana Jul 10 '19 at 9:20
  • Thank You very much :) – SebastianT Jul 10 '19 at 9:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.