Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

📷 Instagram API client for the Elixir language (elixir-lang)

NotificationsYou must be signed in to change notification settings

mirko314/elixtagram

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elixtagram is a simple Instagram client for Elixir.

Build StatusInline docsCoverage StatusDeps Statushex.pm versionhex.pm downloadsLicense

I've created an example application with Phoenixhere

Usage

Installation

Add the following to yourmix.exs

...def application do  [mod: {InstagramPhoenixExample, []},   applications: [:elixtagram]]end...defp deps do  [{:elixtagram, "~> 0.6.0"}]...

Configuration

Elixtagram will first look for application variables, then environment variables. This is useful if you want to set application variables locally and environment variables in production (e.g. on Heroku). That being said, I recommend usingDotenv locally.

config/dev.exs

config :elixtagram,  instagram_client_id: "YOUR-CLIENT-ID",  instagram_client_secret: "YOUR-CLIENT-SECRET",  instagram_redirect_uri: "YOUR-REDIRECT-URI"

.env

INSTAGRAM_CLIENT_ID=YOUR-CLIENT-IDINSTAGRAM_CLIENT_SECRET=YOUR-CLIENT-SECRETINSTAGRAM_REDIRECT_URI=YOUR-REDIRECT-URI

You can also configure these programatically at runtime if you wish:

iex(1)> Elixtagram.configure("YOUR-CLIENT-ID", "YOUR-CLIENT-SECRET", "YOUR-REDIRECT-URI"){:ok, []}

Usage

Before using Elixtagram, it needs to be initialised. RunElixtagram.configure/0 orElixtagram.configure/1 before any other commands

Authenticate a user

# Generate a URL to send them toiex(1)> Elixtagram.authorize_url!"https://api.instagram.com/oauth/authorize/?client_id=XXX&redirect_uri=localhost%3A4000&response_type=code"# Instagram will redirect them back to your INSTAGRAM_REDIRECT_URI, so once they're there, you need to catch the url param 'code', and exchange it for an access token.iex(2)> code = "XXXXXXXXXX""XXXXXXXXXX"iex(3)> {:ok, access_token} = Elixtagram.get_token!(code: code){:ok, "XXXXXXXXXXXXXXXXXXXX"}# Now we can optionally set this as the global token, and make requests with it by passing :global instead of a token.iex(4)> Elixtagram.configure(:global, access_token):ok

Unauthenticated endpoints

There are a lot of endpoints you can use without an access token from a user. Most methods can be called in one of three ways, for example:

# Unauthenticatediex(1)> Elixtagram.tag("lifeisaboutdrugs")%Elixtagram.Model.Tag{media_count: 27, name: "lifeisaboutdrugs"}# Explicitly authenticatediex(1)> Elixtagram.tag("lifeisaboutdrugs", "XXXXXXXXXXXXXXXXX")%Elixtagram.Model.Tag{media_count: 27, name: "lifeisaboutdrugs"}# Implicitly authenticated (only works if you have configured a global token)iex(1)> Elixtagram.tag("lifeisaboutdrugs", :global)%Elixtagram.Model.Tag{media_count: 27, name: "lifeisaboutdrugs"}

Authenticated endpoints

Authenticated endpoints are mostly things which are about getting the current user's stuff

iex(1)> Elixtagram.user_feed(%{count: 2}, "XXXXXXXXXXXXXXXXX")[%Elixtagram.Model.Media{...}, %Elixtagram.Model.Media{...}]iex(2)> Elixtagram.user_feed(%{count: 2}, :global)[%Elixtagram.Model.Media{...}, %Elixtagram.Model.Media{...}]

All of the available methods and the ways to call them arein the docs

Running the tests

TL;DR:mix test

Longer answer:

$ mix deps.getRunning dependency resolutionAll dependencies up to date$ mix test...........................................................................................Finished in 17.6 seconds (2.9s on load, 14.7s on tests)91 tests, 0 failuresRandomized with seed 846369$ mix coveralls...........................................................................................Finished in 13.1 seconds (1.9s on load, 11.2s on tests)91 tests, 0 failuresRandomized with seed 972312----------------COV    FILE                                        LINES RELEVANT   MISSED100.0% lib/elixtagram.ex                             806       49        0100.0% lib/elixtagram/api/base.ex                     84       24        0100.0% lib/elixtagram/api/comments.ex                 30        3        0100.0% lib/elixtagram/api/follows.ex                  37        5        0100.0% lib/elixtagram/api/likes.ex                    30        3        0100.0% lib/elixtagram/api/locations.ex                56       12        0100.0% lib/elixtagram/api/media.ex                    37        6        0100.0% lib/elixtagram/api/tags.ex                     33        5        0100.0% lib/elixtagram/api/users.ex                    59       14        0100.0% lib/elixtagram/config.ex                       42       10        0  0.0% lib/elixtagram/exception.ex                     3        0        0  0.0% lib/elixtagram/model.ex                        38        0        0100.0% lib/elixtagram/oauth_strategy.ex               50       13        0100.0% lib/elixtagram/parser.ex                       48       10        0[TOTAL] 100.0%----------------

Status

It's mostly complete, but these things are missing:

  • Pagination of results for certain data types
  • Real time subscriptions
  • Secure requests

Changelog

0.6.0

  • Merge PR which updates the new API url forElixtagram.user_feed/2 (PR #17, thanks @sudostack!)
  • Merge PR which adds support for the newcarousel_media type (PR #19, thanks @mendab1e!)

0.5.1

  • Merge PR which better handles cases where API request limiting kicks in (PR #18, thanks @mendab1e!)

0.5.0

  • Merge PR #16 which implements a paginated version ofElixtagram.tag_recent_media:Elixtagram.tag_recent_media_with_pagination (thanks @mendab1e!)

0.4.0

  • Merge PR #15 from @mendab1e which adds thevideos field toMedia (Thanks!)
  • Update theoauth2 library to version0.9.1 which closes Issue #14 from @radzserg (Thanks, sorry it took me so long to get to this!)
  • Updatehttpoison to0.11.1
  • Updatepoison to3.1.0

0.3.0

  • Change theElixtagram.get_token! function to return a tuple like{:ok, token}
  • Update dependencies
  • Merge apull request which fixes an issue relating to a newer version of OAuth2 (thanks@radzserg)

0.2.9

  • Adduser_recent_media_with_pagination (thanks again@deadkarma!)

0.2.8

0.2.7

  • Add thetype attribute to Media in order to tell the difference between 'image' and 'video' types (thanks@deadkarma!)

0.2.6

  • Add the newcreated_time andusers_in_photo toMedia (thanks@deadkarma!)
  • Add new required OAuth permissions request (thanks@bobishh!)

0.2.5

  • Addcredo indev environment
  • Improve code readability and resolve credo warnings (thanks@rrrene!)

0.2.4

  • Update the OAuth2 library to0.5 (thanks@steffenix!!)
  • add a couple more test cases around pagination to get back to 100% coverage

0.2.3

  • Minor pagination bugfix - was throwing aKeyError when requesting a paginateduser_follows and on the last page of results.

0.2.2

  • Add pagination support foruser_follows, this doesn't break the existinguser_follows/2 anduser_follows/3 API.

0.2.1

  • AddElixtagram.authorize_url!/3, which takes astate argument to pass back to the callback url. This is useful for things like CSRF protection (read more here). This change doesn't break or change the existing API.

0.2.0

  • Change the api ofElixtagram.user_follows/1 &Elixtagram.user_follows/2 (now respectivelyElixtagram.user_follows/2 &Elixtagram.user_follows/3) to accept acount argument.

About

📷 Instagram API client for the Elixir language (elixir-lang)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir100.0%

[8]ページ先頭

©2009-2025 Movatter.jp