Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

instagram-private-api-rn

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instagram-private-api-rn

React Native compatibility layer for instagram-private-api

latest
npmnpm
Version
9.0.4
Version published
Weekly downloads
12
100%
Maintainers
1
Weekly downloads
 
Created
Source

Instagram Private API React Native Compatibility Layer

This package provides a compatibility layer for using the instagram-private-api library in React Native applications. It includes polyfills and replacements for Node.js-specific modules that are not available in React Native.

Installation

# Install the main instagram-private-api library
npm install instagram-private-api

# Install this compatibility layer
npm install instagram-private-api-rn

# Install required dependencies
npm install buffer react-native-randombytes react-native-fast-crypto react-native-rsa-native @dr.pogodin/react-native-fs @react-native-async-storage/async-storage react-native-url-polyfill

# Install additional dependencies for Metro configuration
npm install stream-browserify path-browserify browserify-zlib stream-http https-browserify querystring-es3 os-browserify constants-browserify vm-browserify assert tty-browserify process

Metro Configuration

You need to configure Metro bundler to handle Node.js modules. Create or update your metro.config.js file:

module.exports = {
  resolver: {
    extraNodeModules: {
      // Provide empty implementations or polyfills for Node.js modules
      net: require.resolve('instagram-private-api-rn/polyfills/net'),
      fs: require.resolve('instagram-private-api-rn/polyfills/fs'),
      crypto: require.resolve('instagram-private-api-rn/polyfills/crypto'),
      url: require.resolve('instagram-private-api-rn/polyfills/url'),
      util: require.resolve('instagram-private-api-rn/polyfills/util'),
      events: require.resolve('instagram-private-api-rn/polyfills/events'),
      tls: require.resolve('instagram-private-api-rn/polyfills/tls'),
      buffer: require.resolve('buffer'),
      stream: require.resolve('stream-browserify'),
      path: require.resolve('path-browserify'),
      zlib: require.resolve('browserify-zlib'),
      http: require.resolve('stream-http'),
      https: require.resolve('https-browserify'),
      querystring: require.resolve('querystring-es3'),
      os: require.resolve('os-browserify/browser'),
      constants: require.resolve('constants-browserify'),
      vm: require.resolve('vm-browserify'),
      assert: require.resolve('assert'),
      tty: require.resolve('tty-browserify'),
      'process/browser': require.resolve('process/browser'),
    },
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};

Usage

import { IgApiClient } from 'instagram-private-api';
import { patchAll } from 'instagram-private-api-rn';
import AsyncStorage from '@react-native-async-storage/async-storage';

// Apply all polyfills to make instagram-private-api compatible with React Native
const ig = new IgApiClient();
patchAll({
  IgApiClient,
  storage: AsyncStorage, // Optional: for persistent cookie storage
});

// Now you can use the instagram-private-api library as usual
async function login() {
  ig.state.generateDevice('username');
  await ig.account.login('username', 'password');

  // Do something with the logged in client
  const userFeed = ig.feed.user('some-user-id');
  const posts = await userFeed.items();
  console.log(posts);
}

login().catch(console.error);

Features

This compatibility layer provides polyfills for the following Node.js modules:

  • crypto: Implements cryptographic functions using React Native compatible libraries
  • http: Replaces request/request-promise with a fetch-based implementation
  • buffer: Provides a Buffer implementation for React Native
  • fs: Implements file system operations using @dr.pogodin/react-native-fs
  • cookies: Replaces tough-cookie with a React Native compatible cookie storage
  • util: Provides utility functions like promisify
  • net: Implements network utility functions used by tough-cookie
  • url: Provides URL parsing and formatting functions
  • events: Implements EventEmitter for event handling
  • tls: Provides TLS/SSL functionality for secure connections

Advanced Usage

You can also use individual polyfills if you need more control:

import { IgApiClient } from 'instagram-private-api';
import { patchHttp, patchCrypto, patchBuffer, patchNet, patchUrl, patchEvents, patchTls } from 'instagram-private-api-rn';

// Apply only specific polyfills
patchBuffer();
patchCrypto();
patchNet();
patchUrl();
patchEvents();
patchTls();
patchHttp(IgApiClient);

// Now you can use the instagram-private-api library with these polyfills
const ig = new IgApiClient();
// ...

Dependencies

This package depends on the following libraries:

  • buffer
  • react-native-randombytes
  • react-native-fast-crypto
  • react-native-rsa-native
  • @dr.pogodin/react-native-fs
  • @react-native-async-storage/async-storage
  • react-native-url-polyfill
  • stream-browserify
  • path-browserify
  • browserify-zlib
  • stream-http
  • https-browserify
  • querystring-es3
  • os-browserify
  • constants-browserify
  • vm-browserify
  • assert
  • tty-browserify
  • process

Make sure to install and properly link these dependencies in your React Native project.

Limitations

  • Some advanced cryptographic operations might not work exactly the same as in Node.js
  • File operations are limited to what @dr.pogodin/react-native-fs supports
  • Performance might differ from the Node.js version

License

This package is licensed under the MIT License.

Keywords

instagram

FAQs

Package last updated on 17 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts