# instagram-searchtags

> Instagram scraper searching tags

Latest version **2.0.9** (published 2017-03-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install instagram-searchtags
pnpm add instagram-searchtags
yarn add instagram-searchtags
bun add instagram-searchtags
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.9 |
| Published | 2017-03-30 |
| First published | 2017-03-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ferry Brouwer |
| Maintainers | ferrybrouwer |
| Keywords | instagram, tags, hashtags, search, searchTags, explore, explore/tags, hash |

## Links

- npm: https://www.npmjs.com/package/instagram-searchtags
- Repository: https://github.com/ferrybrouwer/instagram-searchtags
- Homepage: https://github.com/ferrybrouwer/instagram-searchtags#readme
- Issues: https://github.com/ferrybrouwer/instagram-searchtags/issues
- npm.io page: https://npm.io/package/instagram-searchtags

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^2.6.3
- [phantom](https://npm.io/package/phantom.md) ^4.0.1
- [promisify-node](https://npm.io/package/promisify-node.md) ^0.4.0
- [phantomjs-prebuilt](https://npm.io/package/phantomjs-prebuilt.md) ^2.1.14

## Recent versions

- 2.0.9 (latest) — 2017-03-30
- 2.1.0 — 2017-03-25
- 2.0.8 — 2017-03-24
- 2.0.7 — 2017-03-24
- 2.0.6 — 2017-03-22
- 2.0.5 — 2017-03-22
- 2.0.4 — 2017-03-22
- 2.0.3 — 2017-03-22
- 2.0.2 — 2017-03-22
- 2.0.1 — 2017-03-21
- 2.0.0 — 2017-03-21
- 1.0.6 — 2017-03-20
- 1.0.5 — 2017-03-20
- 1.0.4 — 2017-03-20
- 1.0.3 — 2017-03-20
- … 3 more at https://npm.io/package/instagram-searchtags/versions

## README

# Instagram search hashtags

[![npm version](https://badge.fury.io/js/instagram-searchtags.svg)](https://badge.fury.io/js/instagram-searchtags)
[![GitHub release](https://img.shields.io/github/release/ferrybrouwer/instagram-searchtags.svg)](https://github.com/ferrybrouwer/instagram-searchtags)
[![npm](https://img.shields.io/npm/dt/instagram-searchtags.svg)](https://www.npmjs.com/package/instagram-searchtags)


## Why this package?

The [API of instagram](https://www.instagram.com/developer/endpoints/tags/)
limits search for hashtags by authorized user tags only with a limit of 20 images.
The API also has a rate limit.

Before we could easily fetch all tags with the endpoints `/explore/tags`.
Instagram recently authorized these endpoints. Therefore it will not work for
third party apps.


Instead of using the API, this package scrapes data without any limits. It
uses [phantomjs](http://phantomjs.org/) to get the data.


## Install

```
npm install instagram-searchtags --save
```

## Usage

Add the environment variable `DEBUG=instagramsearchtags` to run with debug
information in the console, example:

```
DEBUG=instagramsearchtags node some-script.js
```

### Basic example: fetching 10 hashtag #dog nodes

```javascript
const InstagramSearchTags = require('instagram-searchtags')

// Create instance with your credentials
const searchTags = new InstagramSearchTags({
  username: 'instagram-username-or-email',
  password: 'xxx',
})

// Login Instagram with credentials
searchTags.login()
  .then(() => {

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

    // Fetch 10 latest nodes
    return tag.fetchNodes(10)

  })
  .then((nodes) => {

    // ... do something cool with nodes

    // close connection
    searchTags.close()

  })
  .catch((err) => {

    // close connection
    searchTags.close()

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

  })
```

### See other examples:

- [Fetching nodes](https://github.com/ferrybrouwer/instagram-searchtags/blob/2.0.0/examples/fetch-nodes.md)
- [Manually iterate through pages](https://github.com/ferrybrouwer/instagram-searchtags/blob/2.0.0/examples/manually-iterate-pages.md)
- [Download latest images](https://github.com/ferrybrouwer/instagram-searchtags/blob/2.0.0/examples/download-images.md)

<u>Let's break it down in some basic steps</u>:

  1. Create an instance of `InstagramSearchTags` with your credentials
  2. Login with these credentials with the method `login()`, this method returns a Promise.
  3. After you've successfully logged in, you will be able to create tags with the method `createTag()`. This method returns a `Tag` instance.
  4. With the `Tag` instance you can invoke several fetch methods, such as `fetchNodes()` which returns a Promise with the resolved nodes.
  5. Close the PhantomJS connection with the `close()` method.


## Documentation

### `InstagramSearchTags` Class

The `InstagramSearchTags` Class is the main class to construct and destruct searching Instagram hashtags.

- <u>Create connection</u>:

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

- <u>Create `Tag` instance</u>:

	Method structure _(pseudo code)_:<br />
	`InstagramSearchTags.createTag(:String): Tag`

	```javascript
	const dogTag = searchTags.createTag('dog')
	```

- <u>Close connection</u>:

	Method structure _(pseudo code)_:<br />
	`InstagramSearchTags.close(): Promise.<void>`
	```javascript
	await searchTags.close()
	```

### `Tag` Class

The `Tag` Class is used to create tags and fetch data from it.

- <u>Fetching single page</u>:

	Method structure _(pseudo code)_:<br />
	`Tag.fetchPage(maxId:String): Promise.<Page>`

	*This method fetch a single page object including top_posts etc.<br />
	The parameter `maxId` is the hash for the page to fetch (this is optional).*

	```javascript
	const page = await tag.fetchPage()
	```

- <u>Fetching next page</u>:

	Method structure _(pseudo code)_:<br />
	`Tag.fetchNextPage(): Promise.<Page>`

	*This method fetch the next page. Useful for manually iterate through pages*

	```javascript
	const page = await tag.fetchPage()

	if (page.hasNextPage()) {
	  const nextPage = await tag.fetchNextPage()
	}
	```


- <u>Fetching nodes</u>:

	Method structure _(pseudo code)_:<br />
	`Tag.fetchNodes(maxNodes:Number): Promise.<Array>`

	*This method fetch media nodes with a maximum.
	Internal it uses `fetchPage` and `fetchNextPage` recursively till the nodes Array is constructed.*

	```javascript
	const nodes = await tag.fetchNodes(20)
	```

- <u>Download thumbnail images</u>:

	Method structure _(pseudo code)_:<br />
	`Tag.downloadNodeThumbnailImages(destinationDirectory:String, maxNodes:Number): Promise.<void>`

	*This method fetch media nodes with a maximum `maxNodes` and download image to `destinationDirectory`. It uses the property `thumbnail_src` from a single node.*

	```javascript
	const nodes = await tag.downloadNodeThumbnailImages('./images', 20)
	```

- <u>Download display images</u>:

	Method structure _(pseudo code)_:<br />
	`Tag.downloadNodeDisplayImages(destinationDirectory:String, maxNodes:Number): Promise.<void>`

	*This method fetch media nodes with a maximum `maxNodes` and download image to `destinationDirectory`. It uses the property `display_src` from a single node.*

	```javascript
	const nodes = await tag.downloadNodeDisplayImages('./images', 20)
	```

- <u>Get the total amount of media nodes found for given tag query.</u>:

	Method structure _(pseudo code)_:<br />
	`Tag.getTotalCount(): Promise.<Number>`

	```javascript
	const totalCount = await tag.getTotalCount()
	```

- <u>Get state if has next page</u>:

	Method structure _(pseudo code)_:<br />
	`Tag.hasNextPage(): Boolean`

	```javascript
	const hasNextPage = tag.hasNextPage()
	```


### `Page` Class

The `Page` Class is generated by `Tag` instances. It provide an interface of fetching data.
This class represent a single Instagram query `/explore/tags/${tag}?__a=1` entry.


- <u>Get state if has next page</u>:

	Method structure _(pseudo code)_:<br />
	`page.hasNextPage(): Boolean`

	```javascript
	const hasNextPage = page.hasNextPage()
	```

- <u>Get next page hash (maxId)</u>:

	Method structure _(pseudo code)_:<br />
	`page.getNextPageMaxId(): String|Boolean.<false>`

	*Get the hash `maxId` for the next page. Returns false when there is no next page found.*

	```javascript
	const maxId = page.getNextPageMaxId()
	```

- <u>Get page nodes</u>:

	Method structure _(pseudo code)_:<br />
	`page.getNodes(): Array`

	*Returns all media nodes of page*

	```javascript
	const nodes = page.getNodes()
	```

- <u>Get total result count of tag</u>:

	Method structure _(pseudo code)_:<br />
	`page.getTotalCount(): Number`

	*The result of this method is the same as for `Tag.prototype.getTotalCount()`*

	```javascript
	const totalNodeCount = page.getTotalCount()
	```

---
_Source: https://npm.io/package/instagram-searchtags · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
