instagram api 结果不显示在服务器上但显示在本地主机上
instagram api results not displaying on server but displaying on localhost
我在将 Instagram 中的图片显示到我的网站时遇到问题。在本地主机上测试时一切正常,但是一旦我将代码上传到服务器,图像就不再显示,并且出现了一些错误(我在最后列出了这些错误)。
这是我用来获取图像的代码:
<?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 ?>
我遇到的错误:
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
你想做的是把你的 allow_url_fopen
变成 On
。由于您的主机默认情况下没有打开它。
您可以先尝试在 .htaccess
文件中打开它,方法是:
php_value allow_url_fopen On
如果这不起作用,您也可以尝试创建自己的自定义 php.ini
文件:
allow_url_fopen = On;
我在将 Instagram 中的图片显示到我的网站时遇到问题。在本地主机上测试时一切正常,但是一旦我将代码上传到服务器,图像就不再显示,并且出现了一些错误(我在最后列出了这些错误)。
这是我用来获取图像的代码:
<?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 ?>
我遇到的错误:
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
你想做的是把你的 allow_url_fopen
变成 On
。由于您的主机默认情况下没有打开它。
您可以先尝试在 .htaccess
文件中打开它,方法是:
php_value allow_url_fopen On
如果这不起作用,您也可以尝试创建自己的自定义 php.ini
文件:
allow_url_fopen = On;