Package Exports
- instagram-web-api
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (instagram-web-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A Instagram Private Web API client 🤳✨❤️
Simple, easy and very complete implementation of the Instagram private web API.
- Support for all the main functions of Instagram Web
- Well tested, CI
- All test runs daily
Install
npm install instagram-web-apiUsage
Intance Instagram and call login method; this stores the credentials in memory.
const Instagram = require('instagram-web-api')
const { username, password } = process.env
const client = new Instagram({ username, password })
client
.login()
.then(() => {
client
.getProfile()
.then(console.log)
})Using async/await in Node >= 8
const Instagram = require('instagram-web-api')
const { username, password } = process.env
const client = new Instagram({ username, password })
;(async () => {
await client.login()
const profile = await client.getProfile()
console.log(profile)
})()Save credentials to disk. The method login resolve an Object with credentials, this allows you to save in disk or any database:
// Native
const { existsSync } = require('fs')
const { join: joinPath } = require('path')
// Packages
const Instagram = require('instagram-web-api')
const loadJSON = require('load-json-file')
const writeJSON = require('write-json-file')
const credentialsFile = joinPath(__dirname, 'credentials.json')
;(async () => {
let client
if (existsSync(credentialsFile)) {
client = new Instagram(await loadJSON(credentialsFile))
} else {
const { username, password } = process.env
client = new Instagram({ username, password })
const credentials = await client.login()
await writeJSON(credentialsFile, credentials)
}
// URL or path of photo
const photo = 'https://scontent-scl1-1.cdninstagram.com/t51.2885-15/e35/22430378_307692683052790_5667315385519570944_n.jpg'
// Upload Photo
const { media } = await client.uploadPhoto(photo)
console.log(`https://www.instagram.com/p/${media.code}/`)
})()API Reference
- Instagram
- new Instagram({ username, password, cookies, cookieStore }, { language, proxy })
- .login({ username, password })
- .logout()
- .getHome()
- .getUserByUsername({ username })
- .getActivity()
- .getProfile()
- .updateProfile({ name, email, username, phoneNumber, gender, biography, website, similarAccountSuggestions })
- .changeProfilePhoto({ photo })
- .deleteMedia({ mediaId })
- .uploadPhoto({ photo, caption })
- .uploadStory({ photo, caption })
- .getMediaFeedByLocation({ locationId })
- .getMediaFeedByHashtag({ hashtag })
- .locationSearch({ query, latitude, longitude })
- .getMediaByShortcode({ shortcode })
- .addComment({ mediaId, text })
- .deleteComment({ mediaId, commentId })
- .approve({ userId })
- .ignore({ userId })
- .follow({ userId })
- .unfollow({ userId })
- .block({ userId })
- .unblock({ userId })
- .like({ mediaId })
- .unlike({ mediaId })
- .save({ mediaId })
- .unsave({ mediaId })
- .search({ query, context })
Instagram(credentials, opts)
const client = new Instagram({ username: '', password: '' }, { language: 'es-CL' })Initializes the client.
credentialsusername: The username of accountpassword: The password of accountcookies: An optionalArrayof cookies, only needed for restore session. Default isundefinedcookieStore: An optionalthough-cookiecookie storage, which allows for persistent cookies. Default isundefined
optslanguage: The language of response from API. Default isen-USproxy:Stringof a proxy to tunnel all requests. Default isundefined
login(credentials)
const { username, password, cookies } = await client.login({ username: '', password: '' })Login in the account, this method return an object with the credentials (username, password and cookies) for saving the session.
credentialsusername: The username of accountpassword: The password of account
logout()
await client.logout()Logout in the account.
getHome()
const feed = await client.getHome()Get home feed timeline, media shared by the people you follow.
getUserByUsername(params)
const instagram = await client.getUserByUsername({ username: 'instagram' })
const me = await client.getUserByUsername({ username: client.credentials.username })Get user by username, this method not require authentication for public profiles.
paramsusername: The username of the profile
getActivity()
const activity = await client.getActivity()Get activity of account, news following, liked, etc.
getProfile()
const profile = await client.getProfile()Get profile the account
first_name,last_name,username,phone_number,gender,birthday,biography,external_urlandchaining_enabled.
updateProfile(params)
await client.updateProfile({ biography: '❤️', website: 'https://jlobos.com/', gender: 1 })Update profile the account.
paramsname: The full name. Default isemail: The email of account. Default isusername: The username of account. Default isclient.credentials.usernamephoneNumber: The Phone Number. Default isgender:Number1male,2female and3not specifiedbiography: The Bio. Default iswebsite: The Website. Default issimilarAccountSuggestions:BooleanInclude your account when recommending similar accounts people might want to follow. Default istrue
changeProfilePhoto(params)
const fs = require('fs')
const photo = fs.join(__dirname, 'photo.jpg')
await client.changeProfilePhoto({ photo })Change the profile photo.
paramsphoto: AStringof path file or URL
deleteMedia(params)
await client.deleteMedia({ mediaId: '1442533050805297981' })Delete a media, photo, video, etc. by the id.
paramsmediaId: The media id
uploadPhoto(params)
const photo = 'https://scontent-scl1-1.cdninstagram.com/t51.2885-15/e35/16465198_658888867648924_4042368904838774784_n.jpg'
await client.uploadPhoto({ photo, caption: '❤️' })Upload a photo to Instagram.
paramsphoto: AStringof path file or URLcaption: The caption of photo. Default is
uploadStory(params)
const photo = 'https://scontent-scl1-1.cdninstagram.com/t51.2885-15/e35/16465198_658888867648924_4042368904838774784_n.jpg'
await client.uploadStory({ photo })Upload a story to Instagram, it only work for images (
jpg)
paramsphoto: AStringof path file or URLcaption: The caption of photo. Default is
getMediaFeedByLocation(params)
const location = await client.getMediaFeedByLocation({ locationId: '26914683' })Get latitude, longitude, top posts, last media, country, city, and more related to the location.
paramslocationId: The location id
getMediaFeedByHashtag(params)
const tag = client.getMediaFeedByHashtag({ hashtag: 'unicorn' })Explore last media and top posts feed related to a hashtag.
paramshashtag: A hashtag, not including the "#"
locationSearch(params)
const venues = client.locationSearch({ query: 'chile', latitude: -33.45, longitude: -70.6667 })Search vanues by latitude and longitude.
paramslatitude: Latitudelongitude: Longitudequery: A optional location name. Default is
getMediaByShortcode(params)
const media = await client.getMediaByShortcode({ shortcode: 'BQE6Cq2AqM9' })Get data of a media by the Instagram shortcode
paramsshortcode: A shortcode
addComment(params)
await client.addComment({ mediaId: 1442533050805297981, text: 'awesome' })Add comment to a media item.
paramsmediaId: The media idtext: Comment text
deleteComment(params)
await client.deleteComment({ mediaId: '1442533050805297981', commentId: '17848908229146688' })Delete a comment.
paramsmediaId: The media idcommentId: The comment id
approve(params)
await client.approve({ userId: '1284161654' })Approve a friendship request.
paramsuserId: The user id
ignore(params)
await client.ignore({ userId: '1284161654' })Reject a friendship request.
paramsuserId: The user id
follow(params)
await client.follow({ userId: '1284161654' })Follow a user.
paramsuserId: The user id
unfollow(params)
await client.unfollow({ userId: '1284161654' })Unfollow a user.
paramsuserId: The user id
block(params)
await client.block({ userId: '1284161654' })Block a user.
paramsuserId: The user id
unblock(params)
await client.unblock({ userId: '1284161654' })Unblock a user.
paramsuserId: The user id
like(params)
await client.like({ mediaId: '1442533050805297981' })Like a media item.
paramsmediaId: The media id
unlike(params)
await client.unlike({ mediaId: '1442533050805297981' })Unlike a media item.
paramsmediaId: The media id
save(params)
await client.save({ mediaId: '1442533050805297981' })Save a media item.
paramsmediaId: The media id
unsave(params)
await client.unsave({ mediaId: '1442533050805297981' })Unsave a media item.
paramsmediaId: The media id
search(params)
await client.search({ query: 'unicorn' })Search users, places, or hashtags.
paramsquery: Querycontext: The context of search,hashtag,place,userorblended. Default isblended
License
MIT © Jesús Lobos