Davincible / goinsta

Unofficial Instagram API written in Golang (v2022)
MIT License
182 stars 56 forks source link

Number of comments is always 0 #25

Closed Nonoleg17 closed 2 years ago

Nonoleg17 commented 2 years ago

Hi, I'm testing the collection of posts on instagram and there was a problem that there are no comments when executing func Next in media.go. image Any ideas how to solve the problem?

Davincible commented 2 years ago

Could you be a bit more specific or show some code? What are you running exactly?

Nonoleg17 commented 2 years ago

Using the Next() function, I get posts изображение In it I check the answer(body) изображение I attach a file with the answer (I watched Elon Musk's account) test.txt .

Davincible commented 2 years ago

Turns out Instagram changed their API a bit, they don't return the comment count anymore on the feed endpoint, but added a new endpoint in the lastest commit.

Inside your for loop, add this function call:

        if err := userFeed.GetCommentInfo(); err != nil {
            panic(err)
        }

        for _, post := range userFeed.Latest() {
            fmt.Printf("%d comments found\n", post.CommentInfo.CommentCount)
        }

The newly added comment info struct:

type CommentInfo struct {
    LikesEnabled                   bool          `json:"comment_likes_enabled"`
    ThreadingEnabled               bool          `json:"comment_threading_enabled"`
    HasMore                        bool          `json:"has_more_comments"`
    MaxNumVisiblePreview           int           `json:"max_num_visible_preview_comments"`
    PreviewComments                []interface{} `json:"preview_comments"`
    CanViewMorePreview             bool          `json:"can_view_more_preview_comments"`
    CommentCount                   int           `json:"comment_count"`
    HideViewAllCommentEntrypoint   bool          `json:"hide_view_all_comment_entrypoint"`
    InlineComposerDisplayCondition string        `json:"inline_composer_display_condition"`
    InlineComposerImpTriggerTime   int           `json:"inline_composer_imp_trigger_time"`
}

Let me know if this works for you

Nonoleg17 commented 2 years ago

Thanks, it works.