Code Monkey home page Code Monkey logo

Comments (7)

Silentz0r avatar Silentz0r commented on June 12, 2024 1

Thank you, mind you one last question, if i want to use only 1 shortcode (the last one) how can i do that? I only need the recent one to compare if it's a new post.

nvm, new Array(data[0].node.shortcode) is the answer! Excellent! Thank you.

from instamancer.

ScriptSmith avatar ScriptSmith commented on June 12, 2024

This isn't part of Instamancer's core functionality, but you can write something to do it yourself with Instamancer. There may be other instagram tools that do what you're after, but I'm not aware of any.

For a user this is difficult, because Instamancer doesn't retrieve all of a user's most recent posts unless it's in full mode, and posts are returned out of order in full mode. Also, it's kinda wasteful because it would require you to create and destroy a new browser instance each time you want to check for new posts.

Instead, I'd just do this in a loop every x seconds:

  1. Make an http request to the user's page on instagram with some http library
  2. Parse the data in the line that starts with:
    <script type="text/javascript">window._sharedData =
  3. Look for new post ids
  4. Use Instamancer.post(ids, options) to get the data for new posts

from instamancer.

Silentz0r avatar Silentz0r commented on June 12, 2024

Thank you for your idea, it's awesome. I'm trying to use your library but im getting this:

const Instamancer = require('instamancer');
async function getDataInstagrambyID() {
    let data = await instagramPhotos();
    console.log(Instamancer.post(data[0].node.id))
}
getDataInstagrambyID();

console:
Object [AsyncGenerator] {}

I didn't install Instamancer globally because i don't need it. I just did npm i instamancer --save-dev

Thank you.

EDIT: As you can see, i'm recently learning about coding. I read a little further testing but i'm not sure what type of id should i use. shortcode or id? I learned that i have use .next(); in order to the function starts. But if i use id as '2099751656438958566' or shortcode as B0j0QGulQnm with id using headless: false i get /p/undefined if i use shortcode i get /p/B/ like it's using the first letter only. Could be i'm doing something wrong?

EDIT2: Using silent: false im getting in the console:

B  Total: 5  State: Scraping  Sleeping: 1  Scraped: 0 
0  Total: 5  State: Scraping  Sleeping: 1  Scraped: 0 
j  Total: 5  State: Scraping  Sleeping: 1  Scraped: 0 
...

Like doing letter by letter and not the whole shortcode. I've installed as -g aswell and using the command-line instamancer post [ids] it works, so im clueless, any help would be appreciate it.

npm -v: 6.9.0
node -v: 12.6.0

from instamancer.

ScriptSmith avatar ScriptSmith commented on June 12, 2024

post(ids, options) takes an array of posts, your issue with it only accessing /p/B is because you're only passing it a single string.

Posts on Instagram have a field called id but it can't be used to retrieve posts, so we use the shortcode as the identifier.

Don't worry about global install, that's for the CLI tool.

Adapting your code, it'd look something like this:

const Instamancer = require('instamancer');
async function getDataInstagrambyID() {
    const data = await instagramPhotos();
    const posts = Instamancer.post(data.map(post => post.node.shortcode));
    for await (const post of posts) {
        console.log(post);
    }
}
getDataInstagrambyID();

from instamancer.

Silentz0r avatar Silentz0r commented on June 12, 2024

I'm closing this as resolved, sorry for wasting your time on this. It's working now with your code. Thank you very much, have a nice day. I need much to learn.

from instamancer.

ScriptSmith avatar ScriptSmith commented on June 12, 2024

Great! Don't worry about wasting my time, I'm happy to help.

from instamancer.

ScriptSmith avatar ScriptSmith commented on June 12, 2024

And if you're a new developer, you might find using something like Instaloader or Instalooter to be a bit easier to wrap your head around when you're writing this because there's less async/await involved

from instamancer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.