instagram-private-api
instagram-private-api copied to clipboard
Error when following a user
Bug Report
Form
Requirements
- [x] I've searched the Issues
- [ ] I've read the basic concepts
- [x] I'm using the latest version
- [ ] I've debugged my code using the
DEBUGvariable.
Platform
- [x] I'm using Node.js version
v16.16.0 - [ ] I'm using electron - xd
Description
Getting an error when trying to follow a user,
ig.friendship.create doesn't seem to work
Code
//basically doing this would give the error
ig.friendship.create(58215877889)
//or this
async function followLikers(mediaId) {
const likersFeed = await ig.media.likers(mediaId);
for (let i = 0; i < likersFeed.users.length && i < 10000; i++) {
const liker = likersFeed.users[i];
try {
await ig.friendship.create(liker.pk);
console.log(`Followed user: ${liker.username}`);
} catch (err) {
console.error(`Error following user ${liker.username}:`, err);
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
console.log('Finished following likers.');
}
Error and Output
Error following user fabo.2029: IgNotFoundError: POST /api/v1/friendships/create/58215877889/ - 404 Not Found;
at Request.handleResponseError (c:\Users\e\Documents\NodeJS\Instagram API\node_modules\instagram-private-api\dist\core\request.js:103:20)
at Request.send (c:\Users\e\Documents\NodeJS\Instagram API\node_modules\instagram-private-api\dist\core\request.js:54:28)
at async FriendshipRepository.change (c:\Users\e\Documents\NodeJS\Instagram API\node_modules\instagram-private-api\dist\repositories\friendship.repository.js:59:26)
at async followLikers (c:\Users\e\Documents\NodeJS\Instagram API\index.js:71:7)
at async C:\Users\e\Documents\NodeJS\Instagram API\index.js:30:3 {stack: 'IgNotFoundError: POST /api/v1/friendships/cre…cuments\\NodeJS\\Instagram API\\index.js:30:3', message: 'POST /api/v1/friendships/create/58215877889/ - 404 Not Found; ', name: 'IgNotFoundError', response: IncomingMessage}
IgNotFoundError: POST /api/v1/friendships/create/58215877889/ - 404 Not Found;
at eval (eval-2cf44ba1.repl:1:7)
at followLikers (C:\\Users\\e\\Documents\\NodeJS\\Instagram API\\index.js:74:7)
at async C:\\Users\\e\\Documents\\NodeJS\\Instagram API\\index.js:30:3
Any updates?
Try this
const userId = await ig.user.getIdByUsername('username')
// const follow = await ig.friendship.create(userId)
const response = await ig.request.send({
url: `/api/v1/friendships/create/${userId}/`,
method: 'POST',
form: ig.request.sign({
_csrftoken: ig.state.cookieCsrfToken,
target_user_id: userId,
radio_type: ig.state.radioType,
_uid: ig.state.cookieUserId,
device_id: ig.state.deviceId,
_uuid: ig.state.uuid,
media_id_attribution: undefined,
}),
})
const data = response.body.friendship_status
console.log('Response Data', data)
Try this
const userId = await ig.user.getIdByUsername('username') // const follow = await ig.friendship.create(userId) const response = await ig.request.send({ url: `/api/v1/friendships/create/${userId}/`, method: 'POST', form: ig.request.sign({ _csrftoken: ig.state.cookieCsrfToken, target_user_id: userId, radio_type: ig.state.radioType, _uid: ig.state.cookieUserId, device_id: ig.state.deviceId, _uuid: ig.state.uuid, media_id_attribution: undefined, }), }) const data = response.body.friendship_status console.log('Response Data', data)
its works