【问题标题】:Tumblr V2 API PHP wrapperTumblr V2 API PHP 包装器
【发布时间】:2012-10-17 10:48:55
【问题描述】:

我正在尝试使用 https://github.com/gregavola/tumblrPHP 上提供的 TumblrPHP 包装器将 Tumblr 博客集成到我的网站中。这是我用来查看我网站上的帖子的代码:

<?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。

感谢您的支持。

【问题讨论】:

    标签: php blogs tumblr


    【解决方案1】:

    我能够通过将 $post['type'] 替换为 $post->type 等来完成这项工作。

    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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-12
      • 2014-02-16
      • 2011-12-01
      相关资源
      最近更新 更多