Technorati API教程

最近在做一个WP插件,需要用到一些博客的排名等信息,ALEXA也提供,Technorati也有,但权衡一下,还是决定用Technorati的数据更好。Technorati是一家比较专注于WEB2.0的博客网站,它提供了博客搜索、博客排名、反向链接搜索、TAG归类搜索等服务。相比Alexa的工具条统计,它依据博客的反向链接等数据进行排名,数据更加客观。

选择Technorati更重要的是Technorati提供了完整的API接口以供应用,虽然ALEXA也提供了接口,却是要收费的,似乎是千次查询$0.1,这让大多数非商业应用的人无法接受。当然Alexa也有几个工具栏的接口被破解后可以盗用,不过个人认为Technorati的数据质量要好于Alexa,决定在插件中使用Technorati的数据。

使用Technorati,先要注册一个Technorati账户,接着访问http://technorati.com/developers/apikey.html,免费获取一个API KEY 如 dfe71294d89ebbca982c98ecd73c96d5 ,正常情况下,一个API KEY每天可以查询500次,这对于一个WP插件应该是足够应用了。


API KEY

如何应用?Technorati提供了包括博客信息,博客搜索,博客反向链接在内的多种搜索服务的接口,可以访问这里获得更多信息。


Technorati提供的接口类型

以我需要用到的博客信息为例

访问http://api.technorati.com/bloginfo?key=[apikey]&url=[blog url],其中[apikey]替换为API KEY,[blog url]就是要查询的博客URL,如 http://photozero.net (http:// 可省略),在PHP文件中用 file_get_contents() 或 fsockopen() 等方式访问,获取返回内容如:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- generator="Technorati API version 1.0" -->
  3. <!DOCTYPE tapi PUBLIC "-//Technorati, Inc.//DTD TAPI 0.02//EN" "http://api.technorati.com/dtd/tapi-002.xml">
  4. <tapi version="1.0">
  5. <document>
  6. <result>
  7. <url>http://photozero.net</url>
  8. <weblog>
  9. <name>零号相册</name>
  10. <url>http://photozero.net</url>
  11.  
  12. <rssurl>http://photozero.net/feed/rss/</rssurl>
  13. <atomurl>http://photozero.net/feed/</atomurl>
  14. <inboundblogs>16</inboundblogs>
  15. <inboundlinks>23</inboundlinks>
  16. <lastupdate>2008-07-20 03:52:34 GMT</lastupdate>
  17. <rank>446726</rank>
  18.  
  19. <authors>
  20. </authors>
  21. </weblog>
  22. <inboundblogs>16</inboundblogs>
  23. <inboundlinks>23</inboundlinks>
  24. </result>
  25. </document>
  26. </tapi>

这里面包括了博客名,博客URL,博客排名,博客RSS地址,反向链接等多种信息,是不是很齐全?

再来一个博客TAG搜索的示范,显示你的博客里有哪些热门TAG,访问
http://api.technorati.com/blogposttags?key=[apikey]&url=[blog URL]
照例把[apikey]替换为API KEY,把[blog URL]替换为 http://photozero.net,就会返回我的博客中的TAG(分类也算在TAG里面了)

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- generator="Technorati API version 1.0 /blogposttags" -->
  3. <!DOCTYPE tapi PUBLIC "-//Technorati, Inc.//DTD TAPI 0.02//EN" "http://api.technorati.com/dtd/tapi-002.xml">
  4. <tapi version="1.0">
  5. <document>
  6. <result>
  7. <querycount>20</querycount>
  8. </result>
  9. <item>
  10. <tag>Free Talk</tag>
  11. <posts>17</posts>
  12. </item>
  13. <item>
  14. <tag>wordpress</tag>
  15.  
  16. <posts>13</posts>
  17. </item>
  18. <item>
  19. <tag>Free_talk</tag>
  20. <posts>9</posts>
  21. </item>
  22. <item>
  23. <tag>Plugin</tag>
  24. <posts>7</posts>
  25. </item>
  26. <item>
  27. <tag>WAP</tag>
  28.  
  29. <posts>6</posts>
  30. </item>
  31. <item>
  32. <tag>PHP</tag>
  33. <posts>5</posts>
  34. </item>
  35. <item>
  36. <tag>Server</tag>
  37. <posts>4</posts>
  38. </item>
  39. <item>
  40. <tag>Mobile</tag>
  41.  
  42. <posts>3</posts>
  43. </item>
  44. <item>
  45. <tag>Baidu</tag>
  46. <posts>2</posts>
  47. </item>
  48. <item>
  49. <tag>Blog</tag>
  50. <posts>2</posts>
  51. </item>
  52. <item>
  53. <tag>Google</tag>
  54.  
  55. <posts>2</posts>
  56. </item>
  57. <item>
  58. <tag>Javascript</tag>
  59. <posts>2</posts>
  60. </item>
  61. <item>
  62. <tag>Yahoo</tag>
  63. <posts>2</posts>
  64. </item>
  65. <item>
  66. <tag>chinese</tag>
  67.  
  68. <posts>2</posts>
  69. </item>
  70. <item>
  71. <tag>DreamHost</tag>
  72. <posts>2</posts>
  73. </item>
  74. <item>
  75. <tag>web20</tag>
  76. <posts>1</posts>
  77. </item>
  78. <item>
  79. <tag>Ajax</tag>
  80.  
  81. <posts>1</posts>
  82. </item>
  83. <item>
  84. <tag>Apple</tag>
  85. <posts>1</posts>
  86. </item>
  87. <item>
  88. <tag>iPhone</tag>
  89. <posts>1</posts>
  90. </item>
  91. <item>
  92. <tag>IP</tag>
  93.  
  94. <posts>1</posts>
  95. </item>
  96. </document>
  97. </tapi>

好了,其他几种应用就不多介绍了,如果有需要应用相关服务的不妨一试。这里推荐一个老外Kailash Nadh写的Technorati API应用的PHP类——Duck Soup,到他主页下载这个库,里面包含了一个应用范本,用这个代码就可以轻松应用Technorati服务了,不用再自己弄一些fsockopen的下载类了。

此条目发表在 PHP 分类目录,贴了 , , 标签。将固定链接加入收藏夹。

Technorati API教程》有 2 条评论

  1. Dianso 说:

    哈哈,你真有激情啊,一直连续不断做插件,我支持你,这个插件出来了我一定使用