Instagram post 的标题显示不正确

Instagram post's caption is not showing properly

我正在尝试获取带有字幕的 instagram 个人资料 post,除字幕外一切正常。 它显示:[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);
    }
  });

我该如何解决这个问题?

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