在java中使用snipplr API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在java中使用snipplr API相关的知识,希望对你有一定的参考价值。

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package net.hazra.xmlrpctutorial;
  7.  
  8. import java.net.URL;
  9. import java.util.*;
  10. import java.util.Vector;
  11. import org.apache.xmlrpc.client.XmlRpcClient;
  12. import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
  13.  
  14.  
  15.  
  16.  
  17.  
  18. public class Main {
  19.  
  20. private static String keyId = "your key id";
  21.  
  22. public static void main( String args[] ) throws Exception {
  23.  
  24. XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
  25. config.setServerURL(new URL("http://snipplr.com/xml-rpc.php"));
  26.  
  27. XmlRpcClient client = new XmlRpcClient();
  28. client.setConfig(config);
  29.  
  30. Vector params = new Vector();
  31. params.addElement(keyId);
  32.  
  33.  
  34. Object[] results = (Object[]) client.execute( "snippet.list", params );
  35.  
  36. if ( results != null ) {
  37. HashMap r = (HashMap) results[0];
  38. Set keys = r.keySet();
  39. Collection values = r.values();
  40.  
  41. System.out.println(keys);
  42. System.out.println(values);
  43. }
  44.  
  45. }
  46. }

以上是关于在java中使用snipplr API的主要内容,如果未能解决你的问题,请参考以下文章

Snipplr API ruby库

将代码段发布到Snipplr

从Snipplr获取一个代码片段

使用Groovy和Apache XML-RPC访问SNIPPLR

使用PHP将twitter搜索API中的tweets保存到MySQL数据库中

--Snipplr—解决方法:注释中的代码