【问题标题】:Get total number of followers获取关注者总数
【发布时间】:2014-05-27 14:40:10
【问题描述】:

我使用下面的代码来获取我的 Instagram 帐户的关注者并在我的网站上显示个人资料图片。这工作正常。我还想做的是显示我网站上的关注者总数,这是我需要帮助的。

下面是完整的代码,如您所见,我已尝试使用“data.counts.followed_by”。这给了我以下错误:“Uncaught TypeError: Cannot read property 'followed_by' of undefined”。

我怎样才能实现我想要的?

$(document).ready(function() {

    var $access_token = '{access-token}';
    pollInstagram('https://api.instagram.com/v1/users/xxxxx/followed-by?access_token=xxxxx&count=15');
});

function pollInstagram(next_url, count){

    $.ajax({
        method: "GET",
        url: next_url,
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "jsonpcallback",
        success: function(data) {
            $.each(data.data, function(i, item) {
                console.log(data.counts.followed_by); <-----        

                var img = '<img style="width: 18%; margin-right: 7px;" src=' + data.data[i].profile_picture + ' />';

                $('#show-images').append(img);
            });
        },
        error: function(jqXHR, textStatus, errorThrown) {
            //alert("Check you internet Connection");
            $("#log").val($("#log").val() + 'Error\n');
        }
    });
}

【问题讨论】:

  • 你试过console.log(data)看看对象的结构吗?

标签: jquery api instagram


【解决方案1】:

【讨论】:

  • 该链接理论上可以回答问题,但it would be preferable将答案的基本部分包含在此处,并提供链接以供参考。
  • 如何链接到Snipt(自动部署到Heroku)[您可以点击下面的按钮自动部署Snipt到Heroku]可以帮忙吗?
【解决方案2】:

谢谢。 我想通了

SELECT follow_to, count(follow_to) as NUM FROM followers GROUP BY follow_to

【讨论】:

  • 这个答案似乎与问题无关,因为只有 JavaScript 代码没有任何直接数据库交互的迹象
猜你喜欢
  • 1970-01-01
  • 2013-07-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-13
  • 1970-01-01
  • 1970-01-01
  • 2019-03-07
  • 2018-08-09
相关资源
最近更新 更多