instagram api结果不显示在服务器上但显示在localhost上

时间:2015-06-28 23:16:11

标签: php instagram-api

我在将Instagram上的图像显示到我的网站时遇到问题。在localhost上测试时,一切都运行得很好,但是一旦我将代码上传到服务器,图像就不再显示了,而且我收到了一些错误(我最后列出了这些错误)。

这是我用来获取图片的代码:

<?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 ?>

我得到的错误:

  

错误1 :PHP警告:file_get_contents()[function.file-get-contents]:   https://在服务器配置中禁用包装器   allow_url_fopen = 0 in   /home/uirqxukx/public_html/TestArea/LuxuriousM/instagramimages.php on   第32行

     

错误2 :PHP警告:file_get_contents(https://api.instagram.com/v1/users/1698502975/media/recent/?access_token=250436950.1677ed0.fba7f937e8ad45aeb16d5ae49e2d6af7&count=30)   [function.file-GET-内容]:   无法打开流:没有找到合适的包装器   /home/uirqxukx/public_html/TestArea/LuxuriousM/instagramimages.php on   第32行

     

错误3 PHP注意:尝试在/home/uirqxukx/public_html/TestArea/LuxuriousM/instagramimages.php中获取非对象的属性   第36行

     

错误4 :PHP警告:在/home/uirqxukx/public_html/TestArea/LuxuriousM/instagramimages.php中为foreach()提供的参数无效   第36行

1 个答案:

答案 0 :(得分:0)

您要做的是将allow_url_fopen转为On。由于您的主机默认情况下没有启用它。

您可以尝试在.htaccess文件中启用它,然后使用:

php_value allow_url_fopen On

如果这不起作用,您可以尝试使用以下方法创建自己的自定义php.ini文件:

allow_url_fopen = On;