0
我正在使用@diegolparra做一個twitter搜索和/或流的示例。需要幫助,訪問更多級別的json/twitter搜索
package controllers
import play.api.mvc.{WebSocket, Action, Controller}
import play.api.libs.functional.syntax._
import play.api.libs.json._
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.ws.WS
import play.api.libs.iteratee.{Iteratee, Concurrent, Enumerator}
import play.api.libs.oauth.{OAuthCalculator, RequestToken, ConsumerKey}
case class Tweet(from: String, text: String)
object Tweets extends Controller {
implicit val tweetReads = (
(__ \ "from_user_name").read[String] and
(__ \ "text").read[String]
)(Tweet)
def tweetList(query: String) = Action {
Async {
val results = 50
val responsePromise =
WS.url("http://search.twitter.com/search.json")
.withQueryString("q" -> query, "rpp" -> results.toString).get
responsePromise.map {
response =>
val tweets = Json.parse(response.body).\("results").as[Seq[Tweet]]
Ok(views.html.tweetlist(tweets))
}
}
}
val consumerKey = ConsumerKey("EBcP4MM9VnI64L8RZLO7g","SVi7XyyNpWzidR2Zx2HVNZ7kZTwFGxpqGKqhOeA")
val accessToken = RequestToken("1228081488-sLSztNAm0ST2kssCkBNRyhSsmk8SP5dtcbX1ZE2", "GxHUymXdyTYRZxw4bbTbgN8Xh53jKxC1KwvgsVwUU")
def stream(keywords: String) = WebSocket.using[String] { request =>
val out: Enumerator[String] = Concurrent.unicast[String](onStart = pushee => {
def twitterIteratee = Iteratee.foreach[Array[Byte]]{ ba =>
val msg = new String(ba, "UTF-8")
pushee.push(msg)
println(msg)
}
WS.url("https://stream.twitter.com/1.1/statuses/filter.json?track=" + keywords)
.sign(OAuthCalculator(consumerKey, accessToken))
.get(headers=> twitterIteratee)
})
val in = Iteratee.ignore[String]
(in, out)
}
}
本示例從twitter搜索的結果中獲取from_user_name和text字段。現在我需要訪問created_at日期和另一個級別(節點用戶)從用戶:profile_image_url和lang獲取。
請幫忙嗎?
謝謝。
謝謝你的幫助@Alban,我會看看... – Eusthace