Giter Site home page Giter Site logo

instagrammer's Introduction

Instagrammer

Instagrammer lets you fetch Instagram user info and posts. This is done by crawling the Instagram web interface, powered by Capybara and a headless Chrome Selenium driver. Automated integration tests are run daily to keep up with possible changes. Read more about the motivation to build this gem.

Build Status Gem Version Maintainability Test Coverage

Installation

Add this line to your application's Gemfile:

gem 'instagrammer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install instagrammer

Usage

User

Create a new user with Instagrammer::User.new("username") or simply Instagrammer.new("username").

Accessing certain properties on an account that is private will result in a PrivateAccount exception. In some cases Instagram doesn't expose any meta data through. In these cases a UserInvalid exception will be raised when accessing certain properties.

Therefor you can check if the account is scrapable with the #public? instance method.

Metadata

The meta counts data is available for both public as well as private accounts:

user = Instagrammer.new("richardvenneman")
user.follower_count # => "204"
user.following_count # => "141"
user.post_count # => "91"

Bio

Bio info is currently available for public accounts only:

user = Instagrammer.new("richardvenneman")
user.name # => "Richard Venneman"
user.username # => "@richardvenneman"
user.avatar # => "https://www.instagram.com/static/images/ico/favicon-200.png/ab6eff..."
user.bio # => "๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Partner at GoNomadic B.V.\nTraveling and building ๐Ÿ™ @cityspotters"
user.url # => "https://www.cityspotters.com/"

Posts

Get the posts for a specific user by using the #get_posts(_limit_) user method.

user = Instagrammer.new("richardvenneman")
user.get_posts(3) # => [#<Instagrammer::Post:70223732051200..>, #<Instagrammer::Post:70223732051200..>, #<Instagrammer::Post:70223732051200..>]

See below for the available post methods

Post

Create a new post with Instagrammer::Post.new("shortcode").

post = Instagrammer::Post.new("Bg3VjfwDRDw")
post.photo? # => true
post.caption # => "๐ŸŒ‹ Mount Agung as seen from ๐ŸŒ‹ Mount Batur just after sunrise ๐ŸŒ…"
post.upload_date # => #<DateTime: 2018-03-28T11:07:26+00:00 ((2458206j,40046s,0n),+0s,2299161j)
post.comment_count # => 3
post.like_count # => 52
post.image_url # => "https://instagram.foem1-1.fna.fbcdn.net/vp/04bffab7e91872110690173cbac1ba28/5D9FDCD0/t51.2885-15/e35/29416707_933709783459981_1377808440356765696_n.jpg?_nc_ht=instagram.foem1-1.fna.fbcdn.net"
post.image_urls # => [{:url=>"https://instagram.foem1-1.fna.fbcdn.net/vp/b962b338f5024309e3242ec3e4158681/5DA27835/t51.2885-15/sh0.08/e35/s640x640/29416707_933709783459981_1377808440356765696_n.jpg?_nc_ht=instagram.foem1-1.fna.fbcdn.net", :width=>640}, {:url=>",https://instagram.foem1-1.fna.fbcdn.net/vp/fb1477d8dc17c9d1a6b36c8107b4a5b2/5DC4FA35/t51.2885-15/sh0.08/e35/s750x750/29416707_933709783459981_1377808440356765696_n.jpg?_nc_ht=instagram.foem1-1.fna.fbcdn.net", :width=>750}, {:url=>",https://instagram.foem1-1.fna.fbcdn.net/vp/04bffab7e91872110690173cbac1ba28/5D9FDCD0/t51.2885-15/e35/29416707_933709783459981_1377808440356765696_n.jpg?_nc_ht=instagram.foem1-1.fna.fbcdn.net", :width=>1080}]

Additionally video posts are somewhat supported as well. Image URLs and like counts are not available for videos.

post = Instagrammer::Post.new("Byx0Nd3A3qr")
post.video? # => true
post.watch_count # => 8035142

Motivation

The problem with scrapers is that they always brake. Instagram/Facebook seems to put in a lot of effort to battle scrapers. This gem tries to approach that challenge a bit different than other Ruby Instagram scrapers. With decent test coverage the integration should be tested continuously and good code quality should allow for quick and easy updates may any changes in the Instagram web interface happen.

The main focus is currently retrieving user posts with some metadata while maintaining a stable implementation. Therefor I try to avoid naive page selectors and rely on meta data where possible.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/richardvenneman/instagrammer.

instagrammer's People

Contributors

dependabot-preview[bot] avatar richardvenneman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.