How to send a POST request to twitter API using Play Framework 2.0 (using Scala)? The API I'm trying to call with both GET and POST, and I successfully called it with GET using this code:
val followersURL = "http://api.twitter.com/1/users/lookup.json?user_id=" + listOfFollowers.mkString(",") WS.url(followersURL) .sign(OAuthCalculator(Twitter.KEY, tokens)) .get() .map{ response => val screenName: Seq[String] = response.json match { case res: JsArray => res.value.map{ value => (value \ "name").toString } case _ => Seq("") } }
Then I tried to call the API using POST as follows:
WS.url("http://api.twitter.com/1/users/lookup.json") .sign(OAuthCalculator(Twitter.KEY, tokens)) .post(Map("user_id"->listOfFollowers)) .map { response => val screenName: Seq[String] = response.json match { case res: JsArray => res.value.map{ value => (value \ "name").toString } case _ => Seq("") } }
This did not work, and I get this exception:
[error] play - Waiting for a promise, but got an error: null java.lang.NullPointerException: null at java.io.Reader.<init>(Unknown Source) ~[na:1.7.0_01] at java.io.InputStreamReader.<init>(Unknown Source) ~[na:1.7.0_01] at oauth.signpost.OAuth.decodeForm(OAuth.java:157) ~[signpost-core.jar:na] at oauth.signpost.AbstractOAuthConsumer.collectBodyParameters(AbstractOAuthConsumer.java:236) ~[signpost-core.jar:na] at oauth.signpost.AbstractOAuthConsumer.sign(AbstractOAuthConsumer.java:96) ~[signpost-core.jar:na] at play.api.libs.oauth.OAuthCalculator.sign(OAuth.scala:106) ~[play_2.9.1.jar:2.0.1]
Since he says the exception is happening on the OAuthCalculator, I am trying to comment on the .sign
call, and it did not raise any exceptions, but of course I did not get the result I needed.
Am I doing something wrong? What am I doing wrong and why? How can I fix the problem?
Thanks before.
source share