Skip to content

Latest commit

 

History

History
92 lines (59 loc) · 1.45 KB

fetch-nodes.md

File metadata and controls

92 lines (59 loc) · 1.45 KB

Example fetching nodes

Example with node v7+ async/await:

index.js:

import InstagramSearchTags from 'instagram-searchtags'

const searchTags = new InstagramSearchTags({
  username: 'instagram-username-or-email',
  password: 'xxx',
})

const example = async() => {
  try {

    // login Instagram
    await searchTags.login()

    // create tag #dog
    const tag = searchTags.createTag('dog')

    // fetching 5 latest #dog nodes
    const nodes = await tag.fetchNodes(5)

    // ... do something cool with nodes

  } catch(err) {

    console.error(`Error: ${err.message}`)

  }

  await searchTags.close()
}

Run script with debug info in console:

DEBUG=instagramsearchtags node --harmony-async-await .

Example with promises:

index.js:

const InstagramSearchTags = require('./dist/index')

const searchTags = new InstagramSearchTags({
  username: 'instagram-username-or-email',
  password: 'xxx',
})

// login Instagram
searchTags.login()
  .then(() => {

    // create tag #dog
    const tag = searchTags.createTag('dog')

    // fetching 5 latest #dog nodes
    return tag.fetchNodes(5)

  })
  .then((nodes) => {

    // ... do something cool with nodes

    // close connection
    searchTags.close()

  })
  .catch((err) => {

    console.error(`Error: ${err.message}`)

    // close connection
    searchTags.close()

  })

Run script with debug info in console:

DEBUG=instagramsearchtags node .