Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edixonalberto/instagrapi
Library to obtain information from an Instagram account in a friendly and intuitive way
https://github.com/edixonalberto/instagrapi
api instragram node portfolio typescript
Last synced: about 1 month ago
JSON representation
Library to obtain information from an Instagram account in a friendly and intuitive way
- Host: GitHub
- URL: https://github.com/edixonalberto/instagrapi
- Owner: EdixonAlberto
- License: mit
- Created: 2020-11-24T20:00:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-17T04:16:01.000Z (over 1 year ago)
- Last Synced: 2024-04-02T02:15:16.925Z (8 months ago)
- Topics: api, instragram, node, portfolio, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/instagrapi
- Size: 593 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Instagrapi
[![](https://img.shields.io/badge/author-Edixon_Piña-yellow?style=for-the-badge)](https://github.com/EdixonAlberto/)
[![](https://img.shields.io/github/license/edixonalberto/instagrapi?style=for-the-badge)](LICENSE)
[![](https://img.shields.io/npm/v/instagrapi?color=CB0000&style=for-the-badge)](https://npmjs.com/package/instagrapi)
[![](https://img.shields.io/npm/dt/instagrapi?color=CB0000&style=for-the-badge)](https://npmjs.com/package/instagrapi)[![](https://img.shields.io/badge/types-TypeScript-blue?style=for-the-badge)](https://github.com/microsoft/TypeScript)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge)](https://github.com/prettier/prettier)Library to obtain information from an Instagram account in a friendly and intuitive way.
The library works as a wrapper for the basic Instagram API, to abstract long or confusing property names and have a
clean and readable data structure.Created with NodeJS and Typescript, all types are exposed for use.
+
💗> 📃 **NOTE:** This library can only be used on the server with Nodejs.
> 📃 **NOTE:** Login to Instagram required to obtain an ID.
> 📃 **NOTE:** In version 4.x.x the "getPost" method no longer works due to changes in the Instagram api.
### 🌐 [Demo Web Site](https://edixonalberto.github.io/instagrapi) ➜
### 🔌 [Example in Nodejs](https://github.com/EdixonAlberto/service-instagrapi) ➜
## Installation
```sh
npm install instagrapi
# or
yarn add instagrapi
```## Usage
First you must get the cookie called "sessionId" by logging in to your instagram account. To do this you must follow
these steps:1. Go to https://www.instagram.com
2. If you don't have a session logged in start one
3. Open development tools witch `Ctrl + Shift + I`
4. Get to the `application` section and then to `Cookies` and select on the right hand side `sessionId`Now you can use the library by instantiating an object and passing the `sessionId` as an argument
```js
const { Instagrapi } = require('instagrapi')const instagrapi = new Instagrapi({
sessionId: process.env.SESSION_ID // Load sessionId from an environment variable
})instagrapi.getProfile('USERNAME').then(profile => {
console.log(profile.followers) // Numbers followers of instagram account
})
```Using typescript and async/await.
```ts
import { Instagrapi, TPost, TComment } from 'instagrapi'const instagrapi = new Instagrapi({
sessionId: process.env.SESSION_ID
})async function getComments(): Promise {
try {
const post: TPost = await instagrapi.getPost('POST_URL')
const comments: string[] = post.previewComments.map((comment: TComment) => comment.content)console.log(comments) // Preview comments of the post
return comments
} catch (error) {
console.error(error)
}
}getComments()
```## Media Files
By default Instagram API return media files via a CDN configured with CORS rules so tha they can only be consumed from
the official page.To work around this you can build your own proxy server and add it in instance confiuration. In this way the library
will automatically add the proxy as a prefix in all the media files that are found in the response.```js
const instagrapi = new Instagrapi({
sessionId: process.env.SESSION_ID,
proxy: 'https://proxy-example.com'
})instagrapi.getProfile('USERNAME').then(profile => {
const imgUrl = profile.image.standardconsole.log(imgUrl) /* https://proxy-example.com/img-url... */
})
```## Methods
- `getProfile(USERNAME)`
Get all the profile information of an instagram account. Receives as argument: `USERNAME`, the username of the instagram
account.Type of output in typescript:
```ts
type TProfile = {
username: string
name: string
image: {
standard: string
hd: string
}
qtyPosts: number
followers: number
following: number
biography: string
externalUrl: string
isBusiness: boolean
isVerified: boolean
isPrivate: boolean
}
```- `getLastPosts(USERNAME)`
Get the last 12 posts of an instagram account. Receives as argument: `USERNAME`, the username of the instagram account.
Type of output in typescript:
```ts
type TLastPosts = Array<{
postUrl: string
image: string
video: null | {
url: string
views: number | null
}
content: string | null
likes: number
qtyComments: number
}>
```- `getPost(POST_URL):`
Get all the details of a post of an instagram account. Receives as argument `POST_URL`, the url of the post on
instagram.Type of output in typescript:
```ts
type TPost = {
postUrl: string
image: {
standard: string
hd: string
}
video: TVideo | null
content: string | null
likes: number
qtyComments: number
gallery: Array
author: TAuthor
coauthors: Array
previewComments: Array
location: null | {
country: string | null
region: string | null
city: string | null
street: string | null
coordinates: {
lat: number
lng: number
}
}
date: string
}
```## License
[MIT](LICENSE) © Edixon Piña