Open DevStreamLine opened 3 years ago
You don't need to do anything special to use this library. It's a regular npm package. Just do npm i instagram-private-api
and you're good to go.
You don't need typescript. If you want to use it then just use the regular setup.
Note: In the examples, the library is imported from ../src
. And you have to replace it with instagram-private-api
(as explained in the readme).
Ahhh, ok. Thank you so much. I am actually on that track now and am hoping it goes well. I was successfully able to get it to deploy with now errors.
You wouldn't be able to point me to an example of posting a story to instagram using the lib, would you?
Thank you for the speedy reply!! I look forward to using the lib.!
You wouldn't be able to point me to an example of posting a story to instagram using the lib, would you?
There's the story-upload.example.
OMG, sorry. I looked at the examples but missed hat one. Thank you and I have everything working!! Best
Sorry, one more question. In the example it has
import { StickerBuilder } from '../src/sticker-builder';
I changed to this, but it is wrong: const { StickerBuilder } = require("sticker-builder");
So, what should it be? AND, how can I determine what goes in place of the path?
I changed to this, but it is wrong: const { StickerBuilder } = require("sticker-builder");
That's wrong because what you're essentially doing is importing the package sticker-builder
, however you want to import the sticker-builder class.
You want to do require('instagram-private-api/dist/sticker-builder')
.
The dist
folder is by typescript and just contains the compiled code.
how can I determine what goes in place of the path?
I'm not sure which path you're referring to.
Well, what I was trying to ask is, how do I know what to put for the other imports. But I looked at the examples and the only imports from the src folder are sticker-builder and IgApiClient and now I know what to put for both off those for require.
If that makes sense, if not, no matter, I understand!
Thanks again you have been most helpful!!
Ok, sorry to ask another question but I basically copied the story-upload code and put it into my function as below, but it givers me this error. Everything seems to be correct and the login works with other functions.
It does publish the image to the story if I comment out the sticker code, so I am assuming I am misunderstanding something with the sticker.
So what do I have wrong? Also, can this publish a video?
2021-07-10T18:02:54.895721+00:00 app[web.1]: You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
2021-07-10T18:02:54.895741+00:00 app[web.1]: IgNotFoundError: GET /api/v1/feed/user/username/story/?supported_capabilities_new=%5B%7B%22name%22%3A%22SUPPORTED_SDK_VERSIONS%22%2C%22value%22%3A%2213.0%2C14.0%2C15.0%2C16.0%2C17.0%2C18.0%2C19.0%2C20.0%2C21.0%2C22.0%2C23.0%2C24.0%2C25.0%2C26.0%2C27.0%2C28.0%2C29.0%2C30.0%2C31.0%2C32.0%2C33.0%2C34.0%2C35.0%2C36.0%2C37.0%2C38.0%2C39.0%2C40.0%2C41.0%2C42.0%2C43.0%2C44.0%2C45.0%2C46.0%2C47.0%2C48.0%2C49.0%2C50.0%2C51.0%2C52.0%2C53.0%2C54.0%2C55.0%2C56.0%2C57.0%2C58.0%2C59.0%2C60.0%2C61.0%2C62.0%2C63.0%2C64.0%2C65.0%2C66.0%22%7D%2C%7B%22name%22%3A%22FACE_TRACKER_VERSION%22%2C%22value%22%3A12%7D%2C%7B%22name%22%3A%22segmentation%22%2C%22value%22%3A%22segmentation_enabled%22%7D%2C%7B%22name%22%3A%22COMPRESSION%22%2C%22value%22%3A%22ETC2_COMPRESSION%22%7D%2C%7B%22name%22%3A%22world_tracker%22%2C%22value%22%3A%22world_tracker_enabled%22%7D%2C%7B%22name%22%3A%22gyroscope%22%2C%22value%22%3A%22gyroscope_enabled%22%7D%5D - 404 Not Found;
2021-07-10T18:02:54.895777+00:00 app[web.1]: at Request.handleResponseError (/app/node_modules/instagram-private-api/dist/core/request.js:102:20)
2021-07-10T18:02:54.895778+00:00 app[web.1]: at Request.send (/app/node_modules/instagram-private-api/dist/core/request.js:53:28)
2021-07-10T18:02:54.895810+00:00 app[web.1]: at async UserStoryFeed.request (/app/node_modules/instagram-private-api/dist/feeds/user-story.feed.js:13:26)
2021-07-10T18:02:54.895844+00:00 app[web.1]: at async UserStoryFeed.items (/app/node_modules/instagram-private-api/dist/feeds/user-story.feed.js:6:26)
2021-07-10T18:02:54.895920+00:00 app[web.1]: at async /app/index.js:394:54
app.post('/MyStory', express.raw({
type: 'application/json'
}), (req, res) => {
console.log('************************* MyStory')
try {
const readFileAsync = promisify(readFile);
const ig = new IgApiClient();
async function login() {
ig.state.generateDevice(process.env.IG_USERNAME);
ig.state.proxyUrl = process.env.IG_PROXY;
await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
}
(async () => {
await login();
const path = './pics/ut.jpg';
const file = await readFileAsync(path);
/**
* You can move and rotate stickers by using one of these methods:
* center()
* rotateDeg(180) rotates 180°
* scale(0.5) scales the sticker to 1/2 of it's size
* moveForward() moves the sticker in front
* moveBackwards() moves the sticker in the background
* right() aligns the sticker to the right
* left() aligns the sticker to the left
* top() aligns the sticker to the top
* bottom() aligns the sticker to the bottom
*
* All of these are chainable e.g.:
* StickerBuilder.hashtag({ tagName: 'tag' }).scale(0.5).rotateDeg(90).center().left()
* You can also set the position and size like this:
* StickerBuilder.hashtag({
* tagName: 'insta',
* width: 0.5,
* height: 0.5,
* x: 0.5,
* y: 0.5,
* })
*/
// these stickers are 'invisible' and not 're-rendered' in the app
await ig.publish.story({
file,
// this creates a new config
stickerConfig: new StickerBuilder()
// these are all supported stickers
.add(
StickerBuilder.hashtag({
tagName: 'insta',
}).center(),
)
.add(
StickerBuilder.mention({
userId: ig.state.cookieUserId,
}).center(),
)
.add(
StickerBuilder.question({
question: 'My Question',
}).scale(0.5),
)
.add(
StickerBuilder.question({
question: 'Music?',
questionType: 'music',
}),
)
// .add(
// StickerBuilder.countdown({
// text: 'My Countdown',
// // @ts-ignore
// endTs: DateTime.local().plus(Duration.fromObject({
// hours: 1
// })), // countdown finishes in 1h
// }),
// )
.add(
StickerBuilder.chat({
text: 'Chat name',
}),
)
.add(
StickerBuilder.location({
locationId: (await ig.locationSearch.index(13, 37)).venues[0].external_id,
}),
)
.add(
StickerBuilder.poll({
question: 'Question',
tallies: [{
text: 'Left'
}, {
text: 'Right'
}],
}),
)
.add(
StickerBuilder.quiz({
question: 'Question',
options: ['0', '1', '2', '3'],
correctAnswer: 1,
}),
)
.add(
StickerBuilder.slider({
question: 'Question',
emoji: '❤',
}),
)
// mention the first story item
.add(StickerBuilder.mentionReel((await ig.feed.userStory('username').items())[0]).center())
// mention the first media on your timeline
.add(StickerBuilder.attachmentFromMedia((await ig.feed.timeline().items())[0]).center())
// you can also set different values for the position and dimensions
.add(
StickerBuilder.hashtag({
tagName: 'insta',
width: 0.5,
height: 0.5,
x: 0.5,
y: 0.5,
}),
)
.build(),
});
})();
} catch (err) {
// On error, log and return the error message
console.log(`❌ MyStory: error message: ${err.message}`);
return res.status(400).send(`Error: ${err.message}`);
}
// Return a response
res.json({
received: true
});
});
.add(StickerBuilder.mentionReel((await ig.feed.userStory('username').items())[0]).center())
This line is responsible for the error (actually ig.feed.userStory('username').items()
rejects).
The user username
doesn't exist. You can remove this. It's just there to get the media-id of the first story.
Hello,
I have a node.js server set up on heroku and I wanted to add the package. Can anyone help me with how I would set up my package.json file (and any others) to also support typescript and how to handle the import's?
I have added the files to my deployment and have changed the imports as shown on the project page, but I get errors when the app starts. My errors right now are with the imports. I have tried to add info to my package to support typescript but then I receive different errors.
I have been googling this for a couple days and would appreciate any help that can be shared.