Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/facebookarchive/instagram-ruby-gem

The official gem for the Instagram API
https://github.com/facebookarchive/instagram-ruby-gem

Last synced: about 2 months ago
JSON representation

The official gem for the Instagram API

Awesome Lists containing this project

README

        

- - -

**_This project is not actively maintained. Proceed at your own risk!_**

- - -

The Instagram Ruby Gem
====================
A Ruby wrapper for the Instagram REST and Search APIs

Installation
------------
gem install instagram

Instagram REST and Search APIs
------------------------------
Our [developer site](http://instagram.com/developer) documents all the Instagram REST and Search APIs.

Blog
----------------------------
The [Developer Blog] features news and important announcements about the Instagram Platform. You will also find tutorials and best practices to help you build great platform integrations. Make sure to subscribe to the RSS feed not to miss out on new posts: [http://developers.instagram.com](http://developers.instagram.com).

Community
----------------------
The [Stack Overflow community](http://stackoverflow.com/questions/tagged/instagram/) is a great place to ask API related questions or if you need help with your code. Make sure to tag your questions with the Instagram tag to get fast answers from other fellow developers and members of the Instagram team.

Does your project or organization use this gem?
-----------------------------------------------
Add it to the [apps](http://github.com/Instagram/instagram-ruby-gem/wiki/apps) wiki!

Sample Application
------------------

```ruby
require "sinatra"
require "instagram"

enable :sessions

CALLBACK_URL = "http://localhost:4567/oauth/callback"

Instagram.configure do |config|
config.client_id = "YOUR_CLIENT_ID"
config.client_secret = "YOUR_CLIENT_SECRET"
# For secured endpoints only
#config.client_ips = ''
end

get "/" do
'Connect with Instagram'
end

get "/oauth/connect" do
redirect Instagram.authorize_url(:redirect_uri => CALLBACK_URL)
end

get "/oauth/callback" do
response = Instagram.get_access_token(params[:code], :redirect_uri => CALLBACK_URL)
session[:access_token] = response.access_token
redirect "/nav"
end

get "/nav" do
html =
"""

Ruby Instagram Gem Sample Application




  1. User Recent Media Calls user_recent_media - Get a list of a user's most recent media


  2. User Media Feed Calls user_media_feed - Get the currently authenticated user's media feed uses pagination


  3. Location Recent Media Calls location_recent_media - Get a list of recent media at a given location, in this case, the Instagram office


  4. Media Search Calls media_search - Get a list of media close to a given latitude and longitude


  5. Popular Media Calls media_popular - Get a list of the overall most popular media items


  6. User Search Calls user_search - Search for users on instagram, by name or username


  7. Location Search Calls location_search - Search for a location by lat/lng


  8. Location Search - 4Square Calls location_search - Search for a location by Fousquare ID (v2)


  9. TagsSearch for tags, view tag info and get media by tag


  10. View Rate Limit and Remaining API callsView remaining and ratelimit info.


"""
html
end

get "/user_recent_media" do
client = Instagram.client(:access_token => session[:access_token])
user = client.user
html = "

#{user.username}'s recent media

"
for media_item in client.user_recent_media
html << "


Like Un-Like
LikesCount=#{media_item.likes[:count]}
"
end
html
end

get '/media_like/:id' do
client = Instagram.client(:access_token => session[:access_token])
client.like_media("#{params[:id]}")
redirect "/user_recent_media"
end

get '/media_unlike/:id' do
client = Instagram.client(:access_token => session[:access_token])
client.unlike_media("#{params[:id]}")
redirect "/user_recent_media"
end

get "/user_media_feed" do
client = Instagram.client(:access_token => session[:access_token])
user = client.user
html = "

#{user.username}'s media feed

"

page_1 = client.user_media_feed(777)
page_2_max_id = page_1.pagination.next_max_id
page_2 = client.user_recent_media(777, :max_id => page_2_max_id ) unless page_2_max_id.nil?
html << "

Page 1


"
for media_item in page_1
html << ""
end
html << "

Page 2


"
for media_item in page_2
html << ""
end
html
end

get "/location_recent_media" do
client = Instagram.client(:access_token => session[:access_token])
html = "

Media from the Instagram Office

"
for media_item in client.location_recent_media(514276)
html << ""
end
html
end

get "/media_search" do
client = Instagram.client(:access_token => session[:access_token])
html = "

Get a list of media close to a given latitude and longitude

"
for media_item in client.media_search("37.7808851","-122.3948632")
html << ""
end
html
end

get "/media_popular" do
client = Instagram.client(:access_token => session[:access_token])
html = "

Get a list of the overall most popular media items

"
for media_item in client.media_popular
html << ""
end
html
end

get "/user_search" do
client = Instagram.client(:access_token => session[:access_token])
html = "

Search for users on instagram, by name or usernames

"
for user in client.user_search("instagram")
html << "
  • #{user.username} #{user.full_name}
  • "
    end
    html
    end

    get "/location_search" do
    client = Instagram.client(:access_token => session[:access_token])
    html = "

    Search for a location by lat/lng with a radius of 5000m

    "
    for location in client.location_search("48.858844","2.294351","5000")
    html << "
  • #{location.name} Map
  • "
    end
    html
    end

    get "/location_search_4square" do
    client = Instagram.client(:access_token => session[:access_token])
    html = "

    Search for a location by Fousquare ID (v2)

    "
    for location in client.location_search("3fd66200f964a520c5f11ee3")
    html << "
  • #{location.name} Map
  • "
    end
    html
    end

    get "/tags" do
    client = Instagram.client(:access_token => session[:access_token])
    html = "

    Search for tags, get tag info and get media by tag

    "
    tags = client.tag_search('cat')
    html << "

    Tag Name = #{tags[0].name}. Media Count = #{tags[0].media_count}.



    "
    for media_item in client.tag_recent_media(tags[0].name)
    html << ""
    end
    html
    end

    get "/limits" do
    client = Instagram.client(:access_token => session[:access_token])
    html = "

    View API Rate Limit and calls remaining"
    response = client.utils_raw_response
    html << "Rate Limit = #{response.headers[:x_ratelimit_limit]}.
    Calls Remaining = #{response.headers[:x_ratelimit_remaining]}"

    html
    end
    ```

    Contributing
    ------------
    In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.

    Here are some ways *you* can contribute:

    * by using alpha, beta, and prerelease versions
    * by reporting bugs
    * by suggesting new features
    * by writing or editing documentation
    * by writing specifications
    * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
    * by refactoring code
    * by closing [issues](http://github.com/Instagram/instagram-ruby-gem/issues)
    * by reviewing patches

    Submitting an Issue
    -------------------
    We use the [GitHub issue tracker](http://github.com/Instagram/instagram-ruby-gem/issues) to track bugs and
    features. Before submitting a bug report or feature request, check to make sure it hasn't already
    been submitted. You can indicate support for an existing issue by voting it up. When submitting a
    bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
    details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
    operating system. Ideally, a bug report should include a pull request with failing specs.

    Submitting a Pull Request
    -------------------------
    1. Fork the project.
    2. Create a topic branch.
    3. Implement your feature or bug fix.
    4. Add documentation for your feature or bug fix.
    5. Run rake doc:yard. If your changes are not 100% documented, go back to step 4.
    6. Add specs for your feature or bug fix.
    7. Run rake spec. If your changes are not 100% covered, go back to step 6.
    8. Commit and push your changes.
    9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
    10. If you haven't already, complete the Contributor License Agreement ("CLA").

    Contributor License Agreement ("CLA")
    _____________________________________
    In order to accept your pull request, we need you to submit a CLA. You only need
    to do this once to work on any of Instagram's or Facebook's open source projects.

    Complete your CLA here: [https://code.facebook.com/cla](https://code.facebook.com/cla)

    Copyright
    ---------
    Copyright (c) 2014, Facebook, Inc. All rights reserved.
    By contributing to Instagram Ruby Gem, you agree that your contributions will be licensed under its BSD license.
    See [LICENSE](https://github.com/Instagram/instagram-ruby-gem/blob/master/LICENSE.md) for details.