从 instagram api 获取帖子计数

Posted

技术标签:

【中文标题】从 instagram api 获取帖子计数【英文标题】:Get post count from instagram api 【发布时间】:2019-11-30 07:53:34 【问题描述】:

我正在尝试获取 Instagram 帐户的帖子计数,我已设法进行关注和关注,但无法正确获取帖子计数。

<?php
$username = 'instagram';

$response = @file_get_contents( "https://www.instagram.com/$username/?__a=1" );

if ( $response !== false ) 
    $data = json_decode( $response, true );
    if ( $data !== null ) 
        $full_name = $data['graphql']['user']['full_name'];
        $follower  = $data['graphql']['user']['edge_followed_by']['count'];
        $follows = $data['graphql']['user']['edge_follow']['count'];
        echo "<p>$full_name</p> <p>$follower followers $follows following.</p>";
    
 else 
echo 'Username not found.';

?>

【问题讨论】:

【参考方案1】:

如果有人需要答案,我设法解决了...

<?php
$username = 'instagram';

$response = @file_get_contents( "https://www.instagram.com/$username/?__a=1" );

if ( $response !== false ) 
   $data = json_decode( $response, true );
   if ( $data !== null ) 
      $full_name = $data['graphql']['user']['full_name'];
      $follower  = $data['graphql']['user']['edge_followed_by']['count'];
      $follows = $data['graphql']['user']['edge_follow']['count'];
      $posts = $data['graphql']['user']['edge_owner_to_timeline_media']['count'];
      echo "<h2><a href='https://www.instagram.com/$username'>$full_name</a></h2> 
      <p><span>$posts posts</span> <span>$follower followers</span>  <span>$follows following</span></p>";
     
 else 
echo 'Username not found.';

?>

您只需前往 https://www.instagram.com/$username/?__a=1 并将 $username 更改为您需要查看的帐户

【讨论】:

以上是关于从 instagram api 获取帖子计数的主要内容,如果未能解决你的问题,请参考以下文章

Instagram api计数不起作用

如何在没有 instagram API 的情况下从 instagram 获取公共用户的所有帖子

从网址获取Instagram帖子的Facebook Media-id

为啥不使用 NodeJS 中的 API 就无法获取所有 Instagram 帖子

Instagram 按名称 API 查找 Hashtag

新的 Instagram API,如何按标签获取帖子