Git Product home page Git Product logo

sinstagram's Introduction

sInstagram Build Status Maven Central Coverage Status Join the chat at https://gitter.im/yukihirai0505/sInstagram

A Scala library for the Instagram API. An asynchronous non-blocking Scala Instagram API Wrapper, implemented using play-json.

Prerequisites

Scala 2.11.+ is supported.

Setup

sbt

If you don't have it already, make sure you add the Maven Central as resolver in your SBT settings:

resolvers += Resolver.sonatypeRepo("releases")

Also, you need to include the library as your dependency:

libraryDependencies += "com.yukihirai0505" % "sinstagram_2.11" % "0.0.7"

http://mvnrepository.com/artifact/com.yukihirai0505/sinstagram_2.11/0.0.7

Usage

Config

Add your client id and client secret as either environment variables or as part of your configuration. sInstagram will look for the following environment variables:

export INSTAGRAM_CLIENT_ID='my-instagram-client-id'
export INSTAGRAM_SECRET='my-instagram-secret'
export INSTAGRAM_CALLBACK_URL='my-instagram-callback-url'

You can also add them to your configuration file, usually called application.conf:

instagram {
  client = {
    id = "my-instagram-client-id"
    secret = "my-instagram-secret"
  }
  callbackUrl = "my-instagram-callback-url"
}

These configurations will be automatically loaded when creating a instagram client, so all you have to do is to initialize your clients as following:

import com.yukihirai0505.sInstagram.InstagramAuth
import com.yukihirai0505.sInstagram.model.{ResponseType, Scope}

val instagramAuth = new InstagramAuth
val scopes: Seq[Scope] = Seq(Scope.BASIC)
val authUrl = instagramAuth.authURL(scopes = scopes)
val accessTokenFuture = instagramAuth.requestToken(code = "the-code-from-callback")

Examples

Alternatively, you can also specify your tokens directly when creating the client:

  import com.yukihirai0505.sInstagram.model.{ResponseType, Scope}
  import com.yukihirai0505.sInstagram.responses.auth.{AccessToken, Auth}
  import com.yukihirai0505.sInstagram.{Instagram, InstagramAuth}

  import scala.concurrent.ExecutionContext.Implicits.global
  import scala.util.{Failure, Success}

  val clientId = "client-id"
  val clientSecret = "client-secret"
  val callbackUrl = "callback-URI"
  val instagramAuth = new InstagramAuth
  val scopes: Seq[Scope] = Seq(Scope.BASIC) // other: Scope.FOLLOWER_LIST, Scope.PUBLIC_CONTENT, Scope.COMMENTS, Scope.LIKES, Scope.RELATIONSHIPS

  // Server-Side login
  // Step 1: Get a URL to call. This URL will return the CODE to use in step 2
  val authUrl = instagramAuth.authURL(clientId, callbackUrl, ResponseType.CODE, scopes)

  // Step 2: Use the code to get an AccessToken
  val accessTokenFuture = instagramAuth.requestToken(clientId, clientSecret, callbackUrl, "the-code-from-step-1")
  val accessToken = accessTokenFuture onComplete {
    case Success(Some(token: AccessToken)) => token
    case Failure(t) => println("An error has occured: " + t.getMessage)
  }

  // Making an authenticated call
  val auth: Auth = AccessToken("an-access-token")
  // If you want to use signed access token
  // val auth: Auth = SignedAccessToken("an-access-token", clientSecret)
  val instagram: Instagram = new Instagram(auth)
  // The library is asynchronous by default and returns a promise.
  val future = instagram.getRecentMediaFeed()

  import scala.language.postfixOps

  future onComplete {
    case Success(body) =>
      body.fold()(b => b.data.foreach(println))
    case Failure(t) => println("An error has occured: " + t.getMessage)
  }

Please look at this file to see all available methods:

https://github.com/yukihirai0505/sInstagram/blob/master/src/main/scala/com/yukihirai0505/sInstagram/Instagram.scala

References

inspired by following source code

sinstagram's People

Contributors

yukihirai0505 avatar

Watchers

James Cloos 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.