Socket
Book a DemoInstallSign in
Socket

insta-api

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insta-api

0.1.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

Instagram

The Instagram Basic Display API allows users of your app to get basic profile information, photos, and videos in their Instagram accounts. The API can be used to access any type of Instagram account but only provides read-access to basic data.

Source

Installation

Add this line to your application's Gemfile:

gem 'insta-api'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install insta-api

Usage

Step 1: Authorization Window URL

Construct the Authorization Window URL below, replacing {app-id} with your Instagram app’s ID (from the App Dashboard > Products > Instagram > Basic Display > Instagram App ID field), replacing {app-secret} with your Instagram app’s ID (from the App Dashboard > Products > Instagram > Basic Display > Instagram App Secret) and {redirect-uri} with your website URL that you provided in Step 2 (Valid OAuth Redirect URIs). The URL must be exactly the same.

> require 'insta'
> options = { redirect_uri: `redirect-uri`, client_id: `app-id`, client_secret: `app-secret` }
> client = Insta::Client.new(options)
> client.auth_url 
    # output: 
    # https://api.instagram.com/oauth/authorize?client_id=#{client_id}&redirect_uri=#{redirect_uri}&scope=#{scope}&response_type=code

Authenticate your Instagram user by signing into the Authorization Window, then click Authorize to grant your app access to your profile data. Upon success, the page will redirect you to the redirect URI you included in the previous step and append an Authorization Code. For example:

https://socialsizzle.herokuapp.com/auth/?code=AQDp3TtBQQ...#_

Note that #_ has been appended to the end of the redirect URI, but it is not part of the code itself. Copy the code (without the #_ portion) so you can use it in the next step.

Step 2: Exchange the Code for a Token

code => ....auth/?code=AQDp3TtBQQ...#_

> client.access_token(code)
# output:
# {
#    "access_token": "IGQVJ...",
#    "user_id": 17841405793187218
# }
Step 3: Exchange a short-lived Instagram User Access Token for a long-lived Instagram User Access Token.

long-lived valid only 60day

    > access_token = "IGQVJ..."
    > client.long_lived_access_token(access_token)
    # output:
    # {
    #   "access_token": "{access-token}",
    #   "token_type": "{token-type}",
    #   "expires_in": {expires-in}
    # }
Step 4: User Info, Media Data
  • create new client
    > require 'insta'
    > access_token = "IGQVJ..."
    > client = Insta::API.new(access_token)
  • user info
    > client.me
  • user media
    > client.media
    > # or
    > client.media(25)
    > # for pagination after above method call, run below method for getting next 25 media
    > client.next_page

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 16 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.