Skip to content

Gimenz/insta-fetcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

82 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Insta Fetcher

HitCount GitHub license Npm package monthly downloads GitHub repo size npm version

Simple Instagram metadata scraping library for Node.js, written in TypeScript.

πŸ“– Full Documentation
β˜• Buy Me a Coffee

Installation

npm install insta-fetcher

Setup

Instagram requires a valid session cookie for most requests. Get yours with getCookie:

import { igApi, getCookie } from 'insta-fetcher';
 
// Get session cookie (only need to do this once)
const cookie = await getCookie('your_username', 'your_password');
console.log(cookie);
 
// Initialize with cookie
const ig = new igApi(cookie);

Note: Save your cookie somewhere (e.g. .env) so you don't need to login every time.

With Proxy

const ig = new igApi(cookie, {
    proxy: {
        host: 'proxy-url',
        port: 'proxy-port',
        auth: {
            username: 'proxy-user',
            password: 'proxy-password'
        }
    }
});

Example

Fetch Post

const post = await ig.fetchPost('https://www.instagram.com/p/xxxxx/');
console.log(post);
 
/*
{
  username: 'fiiyya21',
  name: 'Fiya',
  postType: 'image',
  media_id: '2841182589568357263_3026954032',
  shortcode: 'Cdt6IP7Pd2D',
  taken_at_timestamp: 1652915380,
  likes: 3,
  caption: 'some caption here',
  media_count: 2,
  comment_count: 15,
  video_duration: null,
  music: null,
  links: [
    {
      id: '...',
      url: 'https://...',
      type: 'image',
      dimensions: { height: 720, width: 720 }
    }
  ]
}
*/

Fetch User Info

// Simple user info
const user = await ig.fetchUserV2('username');
console.log(user);
 
// Detailed user info (includes email, phone if public)
const userDetail = await ig.fetchUser('username');
console.log(userDetail);
 
// Get user ID from username
const userId = await ig.getIdByUsername('username');
console.log(userId);

Fetch Stories

const stories = await ig.fetchStories('username');
console.log(stories);
 
/*
{
  username: 'username',
  stories_count: 3,
  stories: [
    {
      type: 'image' | 'video',
      url: 'https://...',
      taken_at: 1652915380,
      expiring_at: 1652915380,
      ...
    }
  ]
}
*/

Fetch Highlights

const highlights = await ig.fetchHighlights('username');
console.log(highlights);
 
/*
{
  username: 'username',
  highlights_count: 5,
  data: [
    {
      title: 'Highlight Title',
      cover: 'https://...',
      media_count: 10,
      highlights_id: '...',
      highlights: [ ... ]
    }
  ]
}
*/

Fetch User Posts (Paginated)

// First page
const posts = await ig.fetchUserPostsV2('username');
 
// Next page using next_max_id
const nextPosts = await ig.fetchUserPostsV2('username', 'next_max_id');

Fetch User Reels

const reels = await ig.fetchUserReel('username');
 
// With pagination
const nextReels = await ig.fetchUserReel('username', 'end_cursor');

Fetch Account Info

// Fetches your own account info based on cookie
const account = await ig.accountInfo();
console.log(account);

Search Followers / Following

const userId = await ig.getIdByUsername('username');
 
const followers = await ig.searchFollower(userId, 'search_term');
const following = await ig.searchFollowing(userId, 'search_term');

Post a Photo

// Post to feed
await ig.addPost('./photo.jpg', 'feed', {
    caption: 'Hello from insta-fetcher!'
});
 
// Post to story
await ig.addPost('./photo.jpg', 'story', {});

Change Profile Picture

await ig.changeProfilePicture('./new_photo.jpg');

Contributing

All contributions are welcome β€” code, bug reports, documentation, or new features.

  1. Fork this repo
  2. Create your branch: git checkout -b feat/your-feature
  3. Commit your changes: git commit -m 'feat: add some feature'
  4. Push to the branch: git push origin feat/your-feature
  5. Open a Pull Request

Related Projects

  • nganu β€” WhatsApp Bot using this library

References

License

MIT

Packages

 
 
 

Contributors