score:4

Accepted answer

I have found this to work:

WS.url("http://api.twitter.com/1/users/lookup.json?user_id="+listOfFollowers)
  .sign(OAuthCalculator(Twitter.KEY, tokens))
  .post("ignored")
  .map { response => 
      val screenName: Seq[String] = response.json match {
          case res: JsArray => res.value.map{ value => (value \ "name").toString }
          case _ => Seq("")
      }
  }

I've also made notes to revisit my code with every major upgrade of Play! to check if the above gets fixed, because this is obviously not right.

score:1

Once you use the Play Framework tools for getting your user's token and secret, you can then use the twitter4j ("org.twitter4j" % "twitter4j-core" % "3.0.3") library to do your posting like this.

import twitter4j.conf.ConfigurationBuilder
import twitter4j.{StatusUpdate, TwitterFactory}

val config = new ConfigurationBuilder()
  .setOAuthConsumerKey(twitterKey)
  .setOAuthConsumerSecret(twitterSecret)
  .setOAuthAccessToken(token)
  .setOAuthAccessTokenSecret(secret)
  .build()
val twitter = new TwitterFactory(config).getInstance()
val status = new StatusUpdate(tweet)
status.media(photoName, stream)
val twitResp = twitter.updateStatus(status)

Annoying to have to use two libraries, and twitter4j isn't async so it's slightly less resource-efficient, but it lets you do real posts which are necessary sometimes.


Related Query

More Query from same tag