tumblr API获取帖子的评论

时间:2011-07-14 06:32:57

标签: php api tumblr

 <?php
 $numPosts = 5;

  $feedURL = "http://#######.tumblr.com/api/read/?num=$numPosts";

   $xml = @simplexml_load_file($feedURL);

  foreach(@$xml->posts->post as $post){
  $posts = (string) $post->{'photo-caption'}; 
  $img = (string) $post->{'photo-url'};
   echo "<div style='width:518px;height:600px;'><div style='width:518px;height:200px;  float:left;'>".'<img style="width:200px;height:200px;" src="' . $img . '" />'."</div><div style='width:518px;height:300px;float:left;'>".$posts."</div></div><br>";}

 ?>
   <div id="disqus_thread"></div>
    <script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'creativescripters'; // required: replace example with your forum shortname

// The following are highly recommended additional parameters. Remove the slashes in front to use.
 var disqus_identifier = 'unique_dynamic_id_1234';
var disqus_url = 'http://creativescripters.com/samples/tab/tab7.html';

/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
    var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
    dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();

我在这里获取帖子,但我想获取给特定帖子的评论..

1 个答案:

答案 0 :(得分:1)

Tumblr中的评论称为笔记。

有关详细信息,请参阅API documentation - / posts - 部分。

对于您的具体问题,您只需在API请求中将布尔notes_info设置为true即可。例如:

一般API帖子请求 http://api.tumblr.com/v2/blog/peacecorps.tumblr.com/posts/text?api_key=PyezS3Q4Smivb24d9SzZGYSuhMNPQUhMsVetMC9ksuGPkK1BTt&notes_info

带有备注的帖子的API请求 http://api.tumblr.com/v2/blog/peacecorps.tumblr.com/posts/text?api_key=PyezS3Q4Smivb24d9SzZGYSuhMNPQUhMsVetMC9ksuGPkK1BTt&notes_info=true

因此,只需更改您的Feed网址即可。您应该好好去。