Last active
December 10, 2015 11:18
-
-
Save songpp/4426786 to your computer and use it in GitHub Desktop.
通过rest api获取diigo收藏夹内容
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.concurrent._ | |
| import scala.concurrent.duration._ | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| import Console.{println => put} | |
| import org.apache.http.impl.client.{BasicResponseHandler, DefaultHttpClient} | |
| import org.apache.http.auth.{UsernamePasswordCredentials, AuthScope} | |
| import org.apache.http.client.methods.HttpGet | |
| import org.apache.http.client.ResponseHandler | |
| import scala.util.parsing.json.JSON | |
| object BookmarkApi{ | |
| val username = "" | |
| val password = "" | |
| val apiKey = "" | |
| def main(args: Array[String]) { | |
| val client: DefaultHttpClient = new DefaultHttpClient() | |
| client.getCredentialsProvider | |
| .setCredentials(new AuthScope("secure.diigo.com", 443), | |
| new UsernamePasswordCredentials(username, password)) | |
| val handler: ResponseHandler[String] = new BasicResponseHandler | |
| val retrieveBookmarks: Future[String] = future { | |
| val get: HttpGet = | |
| new HttpGet(s"https://secure.diigo.com/api/v2/bookmarks?key=$apiKey&user=$username&count=10") | |
| client.execute(get, handler) | |
| } | |
| val r = Await.result(retrieveBookmarks, 5 second) | |
| val result = JSON.parseFull(r) | |
| result match { | |
| case Some((entry: Map[String, _] @unchecked) :: _) => put(entry.keySet) | |
| case _ => put("what !??") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment