Instagram帖子的标题显示不正确

问题描述 投票:0回答:1

我正在尝试获取带字幕的instagram个人资料的帖子,除字幕外,其他一切正常。它显示:[object Object]

我还没有使用过任何api。

我的代码:

function nFormatter(num){
    if(num >= 1000000000){
      return (num/1000000000).toFixed(1).replace(/\.0$/,'') + 'G';
    }
    if(num >= 1000000){
      return (num/1000000).toFixed(1).replace(/\.0$/,'') + 'M';
    }
    if(num >= 1000){
      return (num/1000).toFixed(1).replace(/\.0$/,'') + 'K';
    }
    return num;
  }
  $.ajax({
    url:"https://www.instagram.com/bhudiptaakash?__a=1",
    type:'get',
    success:function(response){
      $(".profile-pic").attr('src',response.graphql.user.profile_pic_url);
      posts = response.graphql.user.edge_owner_to_timeline_media.edges;
      posts_html = '';
      for(var i=0;i<posts.length;i++){
        caption = posts[i].node.edge_media_to_caption;
        likes = posts[i].node.edge_liked_by.count;
        posts_html += '<a href="https://instagram.com/p/'+shortcode+'">: '+caption+';
      }
      $(".posts").html(posts_html);
    }
  });

我该如何解决?

javascript jquery instagram instagram-api instagram-graph-api
1个回答
1
投票

edge_media_to_caption属性的值是这样的对象:

{
    "edges": [{
        "node": {
            "text": "Still alive"
        }
    }]
}

您需要遍历边缘并获得node.text属性。

for (var i = 0; i < posts.length; i++) {
  let caption = posts[i].node.edge_media_to_caption.edges.map(e => e.node.text).join('<br>');
  let likes = posts[i].node.edge_liked_by.count;
  posts_html += '<a href="https://instagram.com/p/' + shortcode + '">: ' + caption + '</a>';
}
© www.soinside.com 2019 - 2024. All rights reserved.