Code Monkey home page Code Monkey logo

Comments (9)

bwyyoung avatar bwyyoung commented on June 12, 2024 1

Ok Sir. Thank you. I will try it.

from instamancer.

ScriptSmith avatar ScriptSmith commented on June 12, 2024

Are you trying to use the instamancer package in the browser, or with an server that the browser connects to?

from instamancer.

bwyyoung avatar bwyyoung commented on June 12, 2024

I am using the instamancer package in a server that the browser connects to. It is an angular app created with NG create.

from instamancer.

bwyyoung avatar bwyyoung commented on June 12, 2024

https://github.com/bwyyoung/DMSolutions_MEAN
Here is the project with the source code I developed so far. It seems instamancer does not play well with angular.

from instamancer.

ScriptSmith avatar ScriptSmith commented on June 12, 2024

I'm not really familiar with Angular and can't get your example running without setting up mongo etc. but isn't this running instamancer in the browser?

from instamancer.

bwyyoung avatar bwyyoung commented on June 12, 2024

Yes, I think so. Sorry. I am a beginner at both Instamancer and Angular, and maybe you have ideas on how best to run this.

from instamancer.

ScriptSmith avatar ScriptSmith commented on June 12, 2024

Well again, I'm not really familiar with angular so I can't tell you how it works best in that ecosystem.

Basically, instamancer needs to run an instance of chrome in order to work, which means it has to run on a server, not in a browser with webpack like it appears to be in your example. For most packages this isn't the case, however most if not all instagram api packages can't be run in a browser because of how restricted browsers are when making http requests.

To run it on a server you need to set up express or something like it, and then the browser can communicate with AJAX. The server will run instamancer and send the results to the browser.

from instamancer.

bwyyoung avatar bwyyoung commented on June 12, 2024

Thank you sir for responding so quickly and frequently.

Ok. I already have Express and Node setup on server side. Would you have an example of how to run Instamancer on server side with express?

from instamancer.

ScriptSmith avatar ScriptSmith commented on June 12, 2024

Here's a quick example:

const express = require('express')
const app = express()
const port = 3000
const instamancer = require('instamancer')

async function getPosts(tag) {
    const hashtag = instamancer.hashtag(tag, {total: 5, silent: true});
    const posts = [];

    for await (const post of hashtag) {
        posts.push(post);
    }

    return posts;
}

let cachedPosts = []

async function getCached() {
    cachedPosts = await getPosts("puppies");
}
setTimeout(getCached, 3000)

app.get('/cached', async (req, res) => {
    res.send(JSON.stringify(cachedPosts));
})

app.get('/live', async (req, res) => {
    const posts = await getPosts(req.params["tag"]);
    res.send(JSON.stringify(posts));
})

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

Visiting localhost:3000/cached will return a list of posts that's updated once every 5 minutes, and visiting localhost:3000/live?tag=your_tag_here will fetch them on-demand.

You have to wait 30-seconds to a minute for the cached posts to appear, and you'll have to wait about as long for something to be returned on the live endpoint. That should get you started.

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.