【问题标题】:Instagram API won't work onlineInstagram API 无法在线工作
【发布时间】:2015-07-29 11:59:03
【问题描述】:

我一直在尝试从 Instagram 获取网站上的照片供稿。照片显示在我的本地主机上,但是当我将编码上传到在线服务器上时,它们没有显示出来,并且出现此错误:

警告:在第 290 行的 H:\root\home\mywebsite\www\site1\index.php 中为 foreach() 提供的参数无效

这是我的代码:

//Instagram
$userid = "103#####10";
$accessToken = "1036#####.ab#####.7b53a###a3b74f9#############d438";
$url = "https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}";
$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); 
$result = json_decode($result);

<?php foreach ($result->data as $post): ?>
    <a class="fancybox" href="<?php echo $post->images->standard_resolution->url ?>" data-fancybox-group="gallery" title="<?php echo $post->caption->text ?>"><img src="<?php echo $post->images->thumbnail->url ?>" alt="<?php echo $post->caption->text ?>" /></a>
<?php endforeach ?>

一段时间以来,我一直试图在网上找到解决此问题的方法。请告诉我我在这里做错了什么。

【问题讨论】:

    标签: php json instagram-api


    【解决方案1】:

    如果它在你的本地而不是你的服务器上工作,是因为 URL 和回调 URL 发生了变化(从你的本地主机到你的服务器)。

    您需要在 Instagram 设置页面中更改您的配置。

    查看信息here

    编辑

    设置您的配置here。您将看到以下菜单。在那里,将 WebsiteURL 和 Redirect URI 更改为您的服务器。

    【讨论】:

    • 您能详细说明一下吗?我已经设置了我的配置,但我认为我不需要它,因为您只需要一个用户 ID 和访问令牌,而不是客户端 ID 和客户端密码来获取用户的图像,对吗?
    • 是的,网站 URL 和重定向 URI 是服务器的。
    • 能否请您复制并粘贴您在浏览器中使用 curl 的 url 并告诉我错误?
    • api.instagram.com/v1/users{$userid}/media/recent/?access_token={$accessToken} 你是这个意思吗?
    • 粘贴到浏览器的结果。请编辑您的帖子并添加它
    猜你喜欢
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多