instagram-private-api

repository·master·Indexed 27 days ago

https://github.com/dilame/instagram-private-api

A NodeJS implementation of the Instagram private API (version 1.46.1) that allows developers to automate interactions such as login, feed browsing, and media management. The library is organized into Repositories for atomic operations, Feeds for paginated endpoints, and Services for high-level complex actions. It includes specialized entities for managing direct threads (DirectThreadEntity), live broadcasts (LiveEntity), media (MediaEntity), and profiles (ProfileEntity).

Tokens
121.4K
Snippets
3
Records
962
Agent score
91%

What's inside instagram-private-api

  1. Use the sticker-builder module to create Instagram stickers

    master

    The sticker-builder module provides a suite of classes to construct various types of Instagram story stickers. You can use the StickerBuilder class along with specific sticker classes to build complex sticker configurations for stories.

    Available sticker classes include:

    • AttachmentSticker
    • ChatSticker
    • CountdownSticker
    • HashtagSticker
    • InstaSticker
    • LocationSticker
    • MentionSticker
    • PollSticker
    • QuestionSticker
    • QuizSticker
    • SliderSticker
  2. Understand core concepts: Repositories, Feeds, and Services

    master

    The library is organized into three main architectural layers:

    Repositories

    Repositories implement low-level atomic operations. Every method in a repository sends exactly one API request. You access them on the IgApiClient instance using their lower-case (camelCase) name without the Repository suffix. Example: ig.addressBook accesses the AddressBookRepository.

    Feeds

    Feeds represent paginated endpoints (e.g., a user's feed). They act as async-iterators/streams and are accessible via ig.feed.feedName() (camelCase). Most feeds require initialization parameters like a user PK.

    Services

    Services provide high-level abstractions to perform complex actions that involve multiple repository calls, such as simulating pre/post-login flows or publishing photos/videos.

  3. Handle Instagram challenges with ChallengeRepository

    master

    The ChallengeRepository is used to handle security challenges (like unusual login attempts or two-factor authentication) encountered during API operations.

    Important: All methods in this repository require State.checkpoint to be populated with a CheckpointResponse. This checkpoint is automatically filled when an IgCheckpointError occurs during an API call.

  4. Perform segmented video uploads

    master

    For segmented video uploads, use the following sequence of methods:

    1. startSegmentedVideo(ruploadParams): Initiates the segmented upload process.
    2. videoSegmentInit(options): Initializes a specific video segment using UploadVideoSegmentInitOptions.
    3. videoSegmentTransfer(options): Transfers the segment data using UploadVideoSegmentTransferOptions.
    4. endSegmentedVideo(__namedParameters): Finalizes the segmented video upload.
  5. Understand the Repository pattern for atomic operations

    master

    The repositories layer in this library is designed for low-level, atomic operations. Each method in a repository must perform at most one API request.

    To perform complex actions that require multiple steps (e.g., publishing a post), you should not attempt to combine multiple requests into a single repository method. Instead, follow this pattern:

    1. Implement Repository Methods: Create individual methods for each atomic API request (e.g., upload.photo and media.configure).
    2. Implement a Service: Create a method in a service layer (e.g., publish) that orchestrates the sequence of repository calls (e.g., calling upload.photo() first, then using the resulting uploadId to call media.configure()).
  6. Install instagram-private-api

    master

    You can install the library via npm or directly from GitHub.

    Security Note: This package uses url-regex-safe to check for links in direct messages. It is highly recommended to manually install re2 to avoid vulnerability to CVE-2020-7661.

    npm install instagram-private-api
    npm install re2
    npm install instagram-private-api
  7. Enable debugging for instagram-private-api

    master

    To view debug information provided by the library, set the DEBUG environment variable in your Node.js environment. The library uses the ig namespace. To see all debug logs, use the ig:* pattern.

    Example:

    DEBUG=ig:* node your-app.js
  8. Handle IgLoginTwoFactorRequiredError during login

    master

    When attempting to log in, Instagram may require two-factor authentication (2FA). If this is the case, the library will throw an IgLoginTwoFactorRequiredError.

    This error is a subclass of IgResponseError and contains a response property of type AccountRepositoryLoginErrorResponse. You should catch this error to initiate your 2FA verification flow (e.g., by requesting a code or using a TOTP token).