I am having a problem with displaying Images from Instagram onto my website. Everything works perfectly fine while testing on localhost, but once I upload the code to a server, the images are no longer displayed, and I'm getting a number of errors (which I have listed at the end).
This is the code I'm using to get the images:
<?php
// Supply a user id and an access token
$userid = "1698502975";
$accessToken = "250436950.8386f68.5be5542d7ede4f0790cfe906c118b6ad";
// $tags = "GraphicDesign";
// Gets our data
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 = file_get_contents("https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}&count=30");
$result = json_decode($result);
?>
<?php foreach ($result->data as $post): ?>
<a class="lightboxX35" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img id="slides" src="<?= $post->images->standard_resolution->url ?>"></a>
<?php endforeach ?>
The errors that I'm getting:
Error 1: PHP Warning: file_get_contents() [function.file-get-contents]: https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/uirqxukx/public_html/TestArea/LuxuriousM/instagramimages.php on line 32
Error2: PHP Warning: file_get_contents(https://api.instagram.com/v1/users/1698502975/media/recent/?access_token=250436950.1677ed0.fba7f937e8ad45aeb16d5ae49e2d6af7&count=30) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/uirqxukx/public_html/TestArea/LuxuriousM/instagramimages.php on line 32
Error 3 PHP Notice: Trying to get property of non-object in /home/uirqxukx/public_html/TestArea/LuxuriousM/instagramimages.php on line 36
Error 4: PHP Warning: Invalid argument supplied for foreach() in /home/uirqxukx/public_html/TestArea/LuxuriousM/instagramimages.php on line 36
What you want to do is turn your allow_url_fopen
to On
. Since your host doesn't have it on by default.
You can start by trying to turn it on in your .htaccess
file, with this:
php_value allow_url_fopen On
If that doesn't work, you can alternatively try creating your own custom php.ini
file with this:
allow_url_fopen = On;