【问题标题】:Get post count from instagram api从 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.';
}
?>

【问题讨论】:

    标签: instagram-api


    【解决方案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 更改为您需要查看的帐户

    【讨论】:

      猜你喜欢
      • 2020-02-07
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多