Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

instagram_api_client

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instagram_api_client

  • 0.2.1
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

Logo Logos

Made by Agilie License Downloads

InstagramApi

Example

A Ruby wrapper for the Instagram API. You can see the api endpoints here https://www.instagram.com/developer/endpoints/

Installation

Install gem in your ruby project

gem install instagram_api_client

or just add to it your Gemfile

gem 'instagram_api_client'

if you are on the Rails and run bundle

Usage

Before you start making the requests to instagram API provide the access_token using the configuration wrapping. If you are going to use Subscriptions you should add client_id and client_secret.

InstagramApi.config do |config|
  config.access_token = 'put your token here'
  config.client_id = 'put your client ID here'
  config.client_secret = 'put your client secret here'
end

As for now Instagram access token doesn't change or expire, so you can use this simple-to-use service to generate it http://services.chrisriversdesign.com/instagram-token/ I the nearest future the OAuth authorization for access token fetching will be implemented.

Resources

The main module of the gem is InstagramApi. It provides a series of methods, regarding each Instagram resource. They are: Users, Media, Comments, Likes, Tags and Locations. So the Users resource methods can be accessed by InstagramApi.user method, Tags by InstagramApi.tag and so on.

The main methods of each resource are show, index, create, destroy and search. The methods and API endpoints correspondence is as follows

Gem ActionAPI Endpoint
User Resource
InstagramApi.user.showGET /users/self
InstagramApi.user(user_id).showGET /users/user_id
InstagramApi.user.recent_mediaGET /users/self/media/recent
InstagramApi.user(user_id).recent_mediaGET /users/user_id/media/recent
InstagramApi.user.liked_mediaGET /users/self/media/liked
InstagramApi.user.search(search_query)GET /users/search
Relationship Endpoints block
InstagramApi.user.followsGET /users/self/follows
InstagramApi.user.followed_byGET /users/self/followed-by
InstagramApi.user.requested_byGET /users/self/requested-by
InstagramApi.user.check_relationship(user_id)GET /users/user_id/relathionship
InstagramApi.user.change_relationship(user_id)POST /users/user_id/relathionship
Media Resource
InstagramApi.media(media_id).showGET /media/media_id
InstagramApi.media.short_code(short_code)GET /media/shortcode/shortcode
InstagramApi.media.search(search_query)GET /media/search
Likes Endpoints block
InstagramApi.media(media_id).likesGET /media/media_id/likes
InstagramApi.media(media_id).add_likePOST /media/media_id/likes
InstagramApi.media(media_id).delete_likeDELETE /media/media_id/likes
Comment Endpoints block
InstagramApi.media(media_id).commentsGET /media/media_id/comments
InstagramApi.media(media_id).add_commentPOST /media/media_id/comments
InstagramApi.media(media_id).delete_comment(comment_id)DELETE /media/media_id/comments/comment_id
Tag Resource
InstagramApi.tag(tag_name).showGET /tags/tag_name
InstagramApi.tag(tag_name).recent_mediaGET /tags/tag_name/media/recent
InstagramApi.tag.search(search_query)GET /tags/search
Location Resource
InstagramApi.location(location_id).showGET /locations/location_id
InstagramApi.location(location_id).recent_mediaGET /locations/location_id/media/recent
InstagramApi.location.search(search_query)GET /locations/search

Each method from the list above accepts a hash as a second argument with additional params according to official instagram developers documentation i.e.

InstagramApi.user.search('mell', {count: 10})
InstagramApi.user('my_user_id').recent_media({min_id: '22721881'})

Search method can get either a query string or a hash. It depends on API requirements, i.e.

InstagramApi.user.search('mell')
InstagramApi.location.search({lat: 33.10, lng: 15.40})

Response is a Hashie::Mash object

Subscriptions

Subscriptions is a useful feature which allows to receive notifications when people who authenticated your app post new media on Instagram. You can find more information on https://www.instagram.com/developer/subscriptions/

Creating a subscription

Creating subscription is very simple. Just refer to the original documentation to check the options available

InstagramApi.subscription.create({
    object: 'user',
    aspect: 'media',
    callback_url: 'http://your.callback/url'
})

This method automatically generates verify_token. However, you can pass your own, if you prefer

InstagramApi.subscription.create({
    object: 'user',
    aspect: 'media',
    callback_url: 'http://your.callback/url',
    verify_token: 'MyCustomVerifyToken'
})
Validating subscription

When you add a subscription, Instagram will send a GET request to your callback URL to verify the existence of the URL. When Instagram has new data, it'll POST this data to your callback URL. To validate the subscription your callback action should validate verify_token from instagram request and response with a hub.challenge parameter value.

You can easily implement it with a single line

# CallbackController

# GET callback url action
def index
    render plain: InstagramApi.subscription.validate(params)
end

or

# CallbackController

# GET callback url action
def index
    render plain: InstagramApi.subscription.validate(params, 'MyCustomVerifyToken')
end

if you are using your own verify_token

Managing subscriptions

You can easily get the list of your subscriptions

InstagramApi.subscription.index

or destroy them if you prefer

InstagramApi.subscription.destroy({object: 'all'})
InstagramApi.subscription.destroy({id: 1})

TODOS

  1. OAuth authorization for access token fetching
  2. Incode Documentation
  3. Cover functionality with tests

Troubleshooting

Problems? Check the Issues block to find the solution or create an new issue that we will fix asap. Feel free to contribute. This project is intended to be a safe, welcoming space for collaboration.

Author

This gem is open-sourced by Agilie Team (info@agilie.com)

Contributor

Sergey Mell

Contact us

If you have any questions, suggestions or just need a help with web or mobile development, please email us at web@agilie.com. You can ask us anything from basic to complex questions.

We will continue publishing new open-source projects. Stay with us, more updates will follow!

License

The gem is available as open source under the MIT License (MIT) Copyright © 2017 Agilie Team

FAQs

Package last updated on 01 Dec 2017

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc