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-api
Usage
Intance Instagram
and call login
method; this stores the credentials in memory.
const Instagram = const username password = processenv const client = username password client
Using async
/await
in Node >= 8
const Instagram = const username password = processenv const client = username password ;async { await client const profile = await client console}
Save cookies to disk by using a though-cookie
store.
// Packagesconst Instagram = const FileCookieStore = const username password = processenv // Only required when no cookies are stored yet const cookieStore = './cookies.json'const client = username password cookieStore ;async { // URL or path of photo const photo = 'https://scontent-scl1-1.cdninstagram.com/t51.2885-15/e35/22430378_307692683052790_5667315385519570944_n.jpg' await client // Upload Photo to feed or story, just configure 'post' to 'feed' or 'story' const media = await client console}
API Reference
- Instagram
- new Instagram({ username, password, cookieStore }, { language, proxy, requestOptions })
- .login({ username, password })
- .logout()
- .getHome()
- .getUserByUsername({ username })
- .getFollowers({ userId, first, after })
- .getFollowings({ userId, first, after })
- .getActivity()
- .getProfile()
- .updateProfile({ name, email, username, phoneNumber, gender, biography, website, similarAccountSuggestions })
- .changeProfilePhoto({ photo })
- .deleteMedia({ mediaId })
- .uploadPhoto({ photo, caption, post })
- .getMediaFeedByLocation({ locationId })
- .getMediaFeedByHashtag({ hashtag })
- .locationSearch({ query, latitude, longitude })
- .getMediaByShortcode({ shortcode })
- .addComment({ mediaId, text })
- .deleteComment({ mediaId, commentId })
- .getChallenge({ challengeUrl })
- .updateChallenge({ challengeUrl, choice, securityCode })
- .resetChallenge({ challengeUrl })
- .replayChallenge({ challengeUrl })
- .approve({ userId })
- .ignore({ userId })
- .follow({ userId })
- .unfollow({ userId })
- .block({ userId })
- .unblock({ userId })
- .like({ mediaId })
- .unlike({ mediaId })
- .save({ mediaId })
- .unsave({ mediaId })
- .search({ query, context })
- .getPhotosByHashtag({hashtag, first, after})
- .getPhotosByUsername({username, first, after})
- .getPrivateProfilesFollowRequests(cursor)
- .getChainsData({ userId })
- .getMediaLikes({ shortcode, first, after })
- .getMediaComments({ shortcode, first, after })
Instagram(credentials, opts)
const client = username: '' password: '' language: 'es-CL'
Initializes the client.
credentials
username
: The username of accountpassword
: The password of accountcookieStore
: An optionalthough-cookie
cookie storage, which allows for persistent cookies. Default isundefined
opts
language
: The language of response from API. Default isen-US
proxy
:String
of a proxy to tunnel all requests. Default isundefined
login(credentials)
const username password cookies = await clientconst authenticated user = await client
Login in the account, this method returns
user
(true
when username is valid) andauthenticated
(true
when login was successful)
credentials
username
: The username of accountpassword
: The password of account
logout()
await client
Logout in the account.
getHome()
const feed = await client
Get home feed timeline, media shared by the people you follow.
params
end_cursor
(String
) for pagination
getUserByUsername(params)
const instagram = await clientconst me = await client
Get user by username, this method not require authentication for public profiles.
params
username
: The username of the profile
getFollowers(params)
const followers = await client
Get followers for given userId. Be aware that the response gets slightly altered for easier usage.
params
userId
: The user idfirst
: Amount of followers to request. Default is20
after
: Optionalend_cursor
(String
) for pagination.
getFollowings(params)
const followings = await client
Get followings for given userId. Be aware that the response gets slightly altered for easier usage.
params
userId
: The user idfirst
: Amount of followings to request. Default is20
after
: Optionalend_cursor
(String
) for pagination.
getActivity()
const activity = await client
Get activity of account, news following, liked, etc.
getProfile()
const profile = await client
Get profile the account
first_name
,last_name
,username
,phone_number
,gender
,birthday
,biography
,external_url
andchaining_enabled
.
updateProfile(params)
await client
Update profile the account.
params
name
: The full name. Default isemail
: The email of account. Default isusername
: The username of account. Default isclient.credentials.username
phoneNumber
: The Phone Number. Default isgender
:Number
1
male,2
female and3
not specifiedbiography
: The Bio. Default iswebsite
: The Website. Default issimilarAccountSuggestions
:Boolean
Include your account when recommending similar accounts people might want to follow. Default istrue
changeProfilePhoto(params)
const fs = const photo = fsawait client
Change the profile photo.
params
photo
: AString
of path file or URL
deleteMedia(params)
await client
Delete a media, photo, video, etc. by the id.
params
mediaId
: The media id
uploadPhoto(params)
const photo = 'https://scontent-scl1-1.cdninstagram.com/t51.2885-15/e35/16465198_658888867648924_4042368904838774784_n.jpg'await client
Upload a photo to Instagram. Only jpeg images allowed.
params
photo
: AString
of path file or URLcaption
: The caption of photo. Default ispost
: The local post,feed
orstory
getMediaFeedByLocation(params)
const location = await client
Get latitude, longitude, top posts, last media, country, city, and more related to the location.
params
locationId
: The location id
getMediaFeedByHashtag(params)
const tag = client
Explore last media and top posts feed related to a hashtag.
params
hashtag
: A hashtag, not including the "#"
locationSearch(params)
const venues = client
Search venues by latitude and longitude.
params
latitude
: Latitudelongitude
: Longitudequery
: A optional location name. Default is
getMediaByShortcode(params)
const media = await client
Get data of a media by the Instagram shortcode
params
shortcode
: A shortcode
addComment(params)
await client
Add comment to a media item.
params
mediaId
: The media idtext
: Comment textreplyToCommentId
: Optional comment id to which to reply
deleteComment(params)
await client
Delete a comment.
params
mediaId
: The media idcommentId
: The comment id
getChallenge(params)
await client
Get information about a challenge.
params
challengeUrl
: AString
with a challenge path
updateChallenge(params)
const challengeUrl = '/challenge/1284161654/a1B2c3d4E6/' await clientawait client
Request or submit a verification code for the given challenge.
params
challengeUrl
: AString
with a challenge pathchoice
:Number
0
for phone and1
for email. Default is ``securityCode
:Number
the received verification code for the challenge. Default is ``
resetChallenge(params)
await client
Reset a challenge to start over again.
params
challengeUrl
: AString
with a challenge path
replayChallenge(params)
await client
Request a new verification message.
params
challengeUrl
: AString
with a challenge path
approve(params)
await client
Approve a friendship request.
params
userId
: The user id
ignore(params)
await client
Reject a friendship request.
params
userId
: The user id
follow(params)
await client
Follow a user.
params
userId
: The user id
unfollow(params)
await client
Unfollow a user.
params
userId
: The user id
block(params)
await client
Block a user.
params
userId
: The user id
unblock(params)
await client
Unblock a user.
params
userId
: The user id
like(params)
await client
Like a media item.
params
mediaId
: The media id
unlike(params)
await client
Unlike a media item.
params
mediaId
: The media id
save(params)
await client
Save a media item.
params
mediaId
: The media id
unsave(params)
await client
Unsave a media item.
params
mediaId
: The media id
search(params)
await client
Search users, places, or hashtags.
params
query
: Querycontext
: The context of search,hashtag
,place
,user
orblended
. Default isblended
getPhotosByHashtag(params)
await client
Get photos for hashtag.
params
hashtag
: AString
with a hashtagfirst
: Anumber
of records to returnafter
: The query cursorString
for pagination
getPhotosByUsername(params)
await client
Gets user photos.
params
username
: AString
with a hashtagfirst
: Anumber
of records to returnafter
: The query cursorString
for pagination
getPrivateProfilesFollowRequests
await client
getChainsData
await client
This will return the similar accounts, that you see, when you click on the ARROW in a profile.
params
userId
: The user id
getMediaLikes(params)
await client
This will return the media likes.
params
shortcode
: The shortcode media like this: https://www.instagram.com/p/B-00000000/, only put shortcode like this : B-000000000first
: Anumber
of records to return max is49
after
: The query cursorString
for pagination
getMediaComments(params)
await client; //The query cursor 'after' maybe return an array, if array you need to convert like this: let pointer = responsepage_infoend_cursor;// this will try to convert array to json stringify try pointer = JSON; pointer = JSON; catche console
This will return the media comments.
params
shortcode
: The shortcode media like this: https://www.instagram.com/p/B-00000000/, only put shortcode like this : B-000000000first
: Anumber
of records to return max is49
after
: The query cursorString
for pagination
License
MIT © Jesús Lobos