从 Instagram api 获取帖子计数

2024-03-25

我正在尝试获取 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.';
}
?>

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

<?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/ https://www.instagram.com/$用户名/?__a=1 并将 $username 更改为您需要查看的帐户

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 Instagram api 获取帖子计数 的相关文章

随机推荐