进程Tumblr JSON提要

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了进程Tumblr JSON提要相关的知识,希望对你有一定的参考价值。

Tumblr API: http://www.tumblr.com/docs/de/api
  1. <?php
  2. $ch = curl_init();
  3. curl_setopt($ch,CURLOPT_URL,"http://demo.tumblr.com/api/read/json");
  4. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  5. $result = curl_exec($ch);
  6. curl_close($ch);
  7.  
  8. $result = str_replace("var tumblr_api_read = ","",$result);
  9. $result = str_replace(';','',$result);
  10. $result = str_replace('u00a0','&nbsp;',$result);
  11.  
  12. $jsondata = json_decode($result,true);
  13. $posts = $jsondata['posts'];
  14. var_dump($posts);
  15. $blogroll = "";
  16. foreach($posts as $post){
  17. $blogroll .= "<p>";
  18. $date = date('d.m.Y',$post['unix-timestamp']);
  19. $blogroll .= $date."<br />";
  20. switch ($post['type']) {
  21. case 'photo':
  22. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a>";
  23. break;
  24.  
  25. case 'link':
  26. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['link-text']."</a><br />";
  27. $blogroll .= substr(strip_tags($post['link-description']),0,100)."...";
  28. break;
  29.  
  30. case 'regular':
  31. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['regular-title']."</a><br />";
  32. $blogroll .= substr(strip_tags($post['regular-body']),0,100)."...";
  33. break;
  34.  
  35. case 'quote':
  36. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
  37. $blogroll .= substr(strip_tags($post['quote-text']),0,100)."...";
  38. break;
  39.  
  40. case 'conversation':
  41. if(empty($post['conversation-title'])){
  42. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
  43. }else{
  44. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".$post['conversation-title']."</a><br />";
  45. }
  46. $blogroll .= substr(nl2br($post['conversation-text']),0,100);
  47. break;
  48.  
  49. case 'audio':
  50. if(empty($post['audio-caption'])){
  51. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a><br />";
  52. }else{
  53. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".strip_tags($post['audio-caption'])."</a><br />";
  54. }
  55. break;
  56.  
  57. default:
  58. $blogroll .= "<a href='".$post['url-with-slug']."' target='_blank'>".str_replace('-',' ',$post['slug'])."</a>";
  59. break;
  60. }
  61. $blogroll .= "</p>";
  62. }
  63.  
  64. echo $blogroll;
  65. ?>

以上是关于进程Tumblr JSON提要的主要内容,如果未能解决你的问题,请参考以下文章

Tumblr JSON API实现

PHP 处理Tumblr JSON Feed

PHP Tumblr JSON API实现

json Tumblr用户列表

JavaScript jq用jquery和Tumblr JSON抓取随机引用

如何显示 JSON 错误消息?