Instagram API 回复为空

Instagram API response empty

我正在尝试从 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;
?>

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

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

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

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

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

  • 创建另一个帐户,我们将其命名为 IAmOther
  • 让 IAmOther 跟随 IAmMain
  • 为 IAmOther 创建一个 Instagram 开发者帐户
  • 在 IAmMain 的开发者页面上,邀请 IAmOther 到您的沙箱(只需在 /developer/clients/[client_ID]/edit->Sandbox 选项卡中输入其用户名 并点击保存更改)
  • 在 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}}

基本上就是您要查找的内容。

希望它能像对我一样好用!