Instagram API wrapper for Scala
Installation
The current release is distributed for Scala 2.11 or later. Add scalagram as a dependency in sbt:
sbt
Add the scalagram dependency:
val scalagram = "com.github.Rydgel" %% "scalagram" % "0.2.0"
Run the test suite
You first need to copy the token.txt.default from the resources and create a token.txt file with a valid access_token in it.
sbt test
Documentation
Examples
import com.rydgel.scalagram._
import com.rydgel.scalagram.responses._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
val clientId = "client-id"
val clientSecret = "client-secret"
val redirectURI = "redirect-URI"
// Server-Side login
// Step 1: Get a URL to call. This URL will return the CODE to use in step 2
val codeUrl = Authentication.codeURL(clientId, redirectURI)
// Step 2: Use the code to get an AccessToken
val accessTokenFuture = Authentication.requestToken(clientId, clientSecret, redirectURI, code = "the-code-from-step-1")
val accessToken = accessTokenFuture onComplete {
case Success(Response(Some(token: AccessToken), _, _, _)) => token
case Failure(t) => println("An error has occured: " + t.getMessage)
}
// Making an authenticated call
val auth = AccessToken("an-access-token")
// The library is asynchronous by default and returns a promise.
val future = Scalagram.userFeed(auth)
future onComplete {
case Success(Response(data, pagination, meta, headers)) => println(data) // do stuff
case Failure(t) => println("An error has occured: " + t.getMessage)
}
// You are still able to perform a synchronous call for quick and dirty stuff
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps
val response: Response[List[Media]] = Await.result(Scalagram.userFeed(auth), 10 seconds)
// Enforce signed parameters
// You can activate this option for all your calls
// You just need to create a SignedAccessToken instead.
// (please read the documentation here https://instagram.com/developer/secure-api-requests/)
val signedAccessToken = SignedAccessToken(accessToken, clientSecret = secret)
// Usage example
Scalagram.comment(signedAccessToken, "media-id", "my comment")
Please look at this file to see all availables methods: https://github.com/Rydgel/scalagram/blob/master/src/main/scala/com/rydgel/scalagram/Scalagram.scala
Todo
Currently subscriptions stuff needs to be done.