WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$json = file_get_contents('https://api.instagram.com/v1/users/userid/media/recent/?access_token=accesstoken');
$a_json = json_decode($json, true);
foreach( $a_json['data'] as $key => $value) {
  $a_images[$value['id']]['link'] = $value['link'];
  $a_images[$value['id']]['url'] = $value['images']['standard_resolution']['url'];
  $a_images[$value['id']]['caption'] = $value['caption']['text'];

echo '<ul>';
$i = 0;
 foreach($a_images as $image)
  if ($i < 3) {
    echo '<li class="large-4 columns">
        <div class="front">
            <a href="'.$image['link'].'" target="_blank">
                <img src="'.$image['url'].'"/>

        <div class="back">
echo '</ul>';

I dont know why but this code seems to be not running on my wordpress. What issues should i be looking at? But when i compile this on some online compiler it works.

Got these errors.

PHP Warning:  file_get_contents(https://api.instagram.com/v1/users/*******/media/recent/?access_token=*****count=50): failed to open stream: HTTP request failed! HTTP/1.1 500 Server Error\r\n in /var/www/vhosts/******* on line 151

PHP Warning:  Invalid argument supplied for foreach() in /var/www/vhosts/*********on line 153

PHP Warning:  Invalid argument supplied for foreach() in /var/www/vhosts/*****on line 162
share|improve this question
I think the problem is with the URL. Try sending a request with the curl command and check if it is the right URL. Also use wp_remote_get() as it is the WordPress way of doing GET requests. – A.Jesin Apr 30 '14 at 9:46
<?php $json = wp_remote_get('https://api.instagram.com/v1/users/id/media/recent/?access_token=‌​access'); $a_json = json_decode($json, true); I tried this and seems to be not working as well is this what you mean? – Jayson Pimentel Apr 30 '14 at 9:56
Print the $json variable and see what is contains - print_r( $json );. It should have the API response at $json['body'] – A.Jesin Apr 30 '14 at 10:13
I got an error WP_Error Object ( [errors] => Array ( [http_request_failed] => Array ( [0] => Operation timed out after 5000 milliseconds with 0 bytes received ) ) [error_data] => Array ( ) ) – Jayson Pimentel Apr 30 '14 at 10:26
I think your host does not allow remote connections from the server. Try the same code locally on MAMP/WAMP/LAMP. – A.Jesin Apr 30 '14 at 10:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.