php显示instragram用户提要

php显示instragram用户提要,php,json,instagram,Php,Json,Instagram,我正在尝试这个教程,但运气不好。我试着输出json对象的计数,当它应该是3时,计数是1。对象->分页,对象元,对象->数据 我在下面的代码中输入了一个假的访问令牌。我使用instagram的访问令牌。您还可以仅使用您的客户端ID执行此查询。我试过了,也犯了同样的错误 当我将这些查询放在instagram api控制台中时,它们会返回正确的json。你们能发现出什么问题吗 以下是教程: 以下是错误: 注意:试图在第41行的PhpstormProjects\untitled\index中获取非对象

我正在尝试这个教程,但运气不好。我试着输出json对象的计数,当它应该是3时,计数是1。对象->分页,对象元,对象->数据

我在下面的代码中输入了一个假的访问令牌。我使用instagram的访问令牌。您还可以仅使用您的客户端ID执行此查询。我试过了,也犯了同样的错误

当我将这些查询放在instagram api控制台中时,它们会返回正确的json。你们能发现出什么问题吗

以下是教程:

以下是错误: 注意:试图在第41行的PhpstormProjects\untitled\index中获取非对象的属性

警告:为第41行的PhpstormProjects\untitled\index中的foreach()提供的参数无效

这是我的密码:

   <?php
   // Supply a user id and an access token
   //$userid = 9999999;
   //$accessToken = "9999999.999999f.cca99999999999";
   //$clientid = "abcdefg999999999999";

   // 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;
     }

     // Pulls and parses data.
     //$result = fetchData("https://api.instagram.com/v1/users/9999999/media/recent/?access_token=9999999.999999f.cca99999999999");
     $result = file_get_contents("https://api.instagram.com/v1/users/9999999/media/recent/?access_token=9999999.999999f.cca99999999999");
     $result = json_decode($result);
     ?>


     <?php foreach ($result->data as $post): ?>
         <!-- Renders images. @Options (thumbnail,low_resolution, high_resolution) -->
         <a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
     <?php endforeach ?>

谢谢你抽出时间


我注释掉了对fetchData()的调用,并使用了file_get_contents(),现在它可以工作了。

仔细检查您与API的连接凭据

注意:试图在第41行的PhpstormProjects\untitled\index中获取非对象的属性意味着没有要迭代的数组,这意味着没有数据返回到
$result

尝试更改:

 <?php foreach ($result->data as $post): ?>

为此:

<?php foreach ((array) $result->data as $post): ?>


这个解决方案对我有效。:)警告消失了

如果添加
var\u dump($result),会得到什么结果
$result=fetchData(“https://api.instagram.com/v1/users/9999999/media/recent/?access_token=9999999.999999f.cca99999999999");?它只是输出布尔值,这意味着您的HTTP查询是错误的。确保您的凭据正确无误。
$result
不应该是
false
。我更改了对fetchData的调用,它可以工作。是的,但有趣的是,如果我在浏览器中输入fetchData参数的确切json调用并下载生成的文件,它就具有正确的json。