2012-10-17 76 views
0

我正在嘗試使用TumblrPHP包裝器https://github.com/gregavola/tumblrPHP將Tumblr博客整合到我的網站中。這是我使用來查看我的網站上的職位代碼:Tumblr V2 API PHP包裝

<?php 
    include ('lib/tumblrPHP.php'); 
    $consumer = 'key'; 
    $secret = 'key'; 
    $tumblr = new Tumblr($consumer, $secret); 
    $posts = $tumblr->get('/blog/nyhetergaius.tumblr.com/posts'); 
    foreach($posts->response->posts as $posts) { 
    ?> 
     <h2><?php echo date('Y-m-d', $post->timestamp) ?></h2> 
     <?php if ($post['type'] == 'regular') { ?> 
     <?php echo $post{'body'}; ?> 
      <?php } ?> 
     <?php 
     if ($post->type == 'photo') { 
      foreach ($post->photos as $photo) { 
       ?> 
       <img src="<?php echo $photo->alt_sizes[1]->url ?>" /> 
       <?php 
      } 
      echo $post->caption; 
     } 
     else 
      echo $post->body; 
     ?> 
    <?php 
} 
?> 

我用我自己的密鑰和祕密密鑰,但即便如此,我只能檢索每個職位的默認日期。我究竟做錯了什麼?是否有更簡單的方式查看帖子,因爲它們出現在博客http://nyhetergaius.tumblr.com/?這是我的網站上顯示的帖子的方式:http://test.gaius.nu/om.php

感謝您的支持。

回答

0

我能夠用$後>等類型替換$信息[「型」],使這項工作..

foreach($posts->response->posts as $posts) { 
    $postDate = date('Y-m-d', $posts->timestamp); 
    echo "<h2>$postDate</h2>"; 
    if ($posts->type == 'regular') { 
     echo $posts->body; 
    } 
    elseif ($posts->type == 'photo') { 
     foreach ($posts->photos as $photo) { 
      $imgURL = $photo->alt_sizes[1]->url; 
      echo "<img src=\"$imgURL\" />"; 
     } 
     echo $posts->caption; 
    } 
    else 
    { 
     echo $posts->body; 
    } 
}