Skip to content

Instantly share code, notes, and snippets.

@zephiransas
Created March 26, 2013 07:45
Show Gist options
  • Save zephiransas/5243747 to your computer and use it in GitHub Desktop.
Save zephiransas/5243747 to your computer and use it in GitHub Desktop.
package controllers
import play.api._
import play.api.mvc._
import oauth.signpost.{OAuth, OAuthProvider, OAuthConsumer}
import oauth.signpost.basic.{DefaultOAuthProvider, DefaultOAuthConsumer}
import oauth.signpost.http.HttpParameters
object Application extends Controller {
val consumer : OAuthConsumer = new DefaultOAuthConsumer("consumer key***********", "consumer secret***************")
val provider : OAuthProvider = new DefaultOAuthProvider(
"https://api.twitter.com/oauth/request_token",
"https://api.twitter.com/oauth/access_token",
"https://api.twitter.com/oauth/authorize")
def index = Action {
val url : String = provider.retrieveRequestToken(consumer, "http://localhost:9000/test")
Redirect(url)
}
def test = Action { request =>
val oauth_token : String = request.getQueryString("oauth_token").get
val oauth_verifier : String = request.getQueryString("oauth_verifier").get
//println(oauth_token)
//println(oauth_verifier)
provider.retrieveAccessToken(consumer, oauth_verifier)
val token : String = consumer.getToken
val tokenSecret : String = consumer.getTokenSecret
val params : HttpParameters = provider.getResponseParameters
val user_id : String = params.get("user_id").first()
val screen_name : String = params.get("screen_name").first()
println(screen_name)
Ok(views.html.index("Your new application is ready."))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment