【问题标题】:Instagram API response emptyInstagram API 响应为空
【发布时间】:2017-07-13 20:52:47
【问题描述】:

我正在尝试从 Instagram API 获取关注列表。我的个人资料是沙盒模式下的管理员。但是来自 API 的数据是空的:

{"pagination": {}, "data": [], "meta": {"code": 200}}

这是我的代码:

<?php
    $authcode = $_REQUEST["code"];
    $clientid = "****";
    $clientsecret = "****";
    if (!$authcode) {
        $url = 'https://api.instagram.com/oauth/authorize/?client_id='.$clientid.'&redirect_uri='.urldecode("http://localhost/ig-following").'&response_type=code&scope=follower_list';
        echo '<a href="'.$url.'">Login</a>';
        exit();
    }
    echo "Get Token..<br><br>";
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,"https://api.instagram.com/oauth/access_token");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'client_id='.$clientid.'&client_secret='.$clientsecret.'&grant_type=authorization_code&redirect_uri='.urldecode("http://localhost/ig-following").'&code='.$authcode);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $server_output = curl_exec ($ch);

    curl_close ($ch);
    $data = json_decode($server_output);
    $username = $data->user->username;
    $access_token = $data->access_token;

    echo 'Token for '.$username.': '.$access_token.'<br><br>';

    $url = 'https://api.instagram.com/v1/users/self/follows?access_token='.$access_token;
    echo 'Request URL: '.$url.'<br><br>';
    $data = file_get_contents($url);
    echo $data;
?>

【问题讨论】:

    标签: php api instagram instagram-api


    【解决方案1】:

    据我所知,您只会获得沙盒用户的关注者/关注者信息。所以你可以邀请一个沙盒用户,开始关注他,然后它应该会显示出来。

    【讨论】:

      【解决方案2】:

      我有同样的错误,这就是为什么你有这个特定的结果:

      在沙盒模式下,一切都好像存在的唯一 Instagram 帐户是 https://www.instagram.com/developer/clients/[client_ID]/edit/ 的“沙盒”选项卡中显示的帐户。我赌五块钱,你会发现那里唯一的用户是……你。

      因此,当 Instagram 告诉您的应用没有人关注您时,这是因为对于 API 的当前状态,您是世界上唯一的 Instagram 用户。

      让我们将您的主帐户命名为 IAmMain。要获取 IAmMain 的关注列表,请按照以下简单步骤操作:

      • 创建另一个帐户,我们将其命名为 IAmOther
      • 让 IAmOther 跟随 IAmMain
      • 为 IAmOther 创建一个 Instagram 开发者帐户
      • 在 IAmMain 的开发者页面上,邀请 IAmOther 加入您的沙盒(只需在 /developer/clients/[client_ID]/edit->沙盒标签中输入其用户名,然后点击保存更改)李>
      • 在 IAmOther 的开发者页面,接受 /developer/clients/sandbox_invites/ 中的邀请

      现在,如果你重新加载 https://api.instagram.com/v1/users/self/follows?access_token=[access_token],你应该会得到类似的东西:

      {"pagination": {}, "data": [{"id": "[10 digits]", "username": "IAmOther", "full_name": "[full name]", "profile_picture": "[url]"}], "meta": {"code": 200}}
      

      这基本上就是你要找的。​​p>

      希望它对我有用!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-05-27
        • 1970-01-01
        • 2015-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-07
        相关资源
        最近更新 更多