3

I have created a simple photo gallery by a hashtag

Using instagram-web-api and electron

Main process:

const Instagram = require('instagram-web-api')
const client = new Instagram({})
ipc.on('get-photos', (event, hashtagFromClient) => {
createPhotoArray()

async function createPhotoArray() {
    let photoArray = []

    let p = await client.getPhotosByHashtag({ hashtag: hashtagFromClient })

    for (let i = 0; i < p.hashtag.edge_hashtag_to_media.edges.length; i++) {
        photoArray.push([p.hashtag.edge_hashtag_to_media.edges[i].node.thumbnail_src, p.hashtag.edge_hashtag_to_media.edges[i].node.edge_liked_by.count])
    }

    event.sender.send('gallery-created', photoArray)
}
})

Render process:

ipc.send('get-photos', game.userData.hashtag)

ipc.on('gallery-created', function (event, photoArr) {
    photoArray = photoArr
    maxNumIMG = photoArray.length
    for (let i = 0; i < photoArray.length; i++) {
        myTimeout = setTimeout(function () { createNewPhoto(photoArray[i][0]) }, gapTime * i)
    }
})

But I see the floating error:

net::ERR_BLOCKED_BY_RESPONSE

How can I fix it?

Alex
  • 31
  • 4
  • https://stackoverflow.com/a/67293454/15404876 Here is the code which mitigates the issue. –  Aug 13 '21 at 10:40

1 Answers1

-1

Instagram has changed it's CORS policy recently. You have to set the request header Host to bypass the policy.

SalmanShariati
  • 3,873
  • 4
  • 27
  • 46