Tumblr V2 API PHP包装器

时间:2012-10-17 10:48:56

标签: php blogs tumblr

我正在尝试使用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

感谢您的支持。

1 个答案:

答案 0 :(得分:0)

我能够通过用$ post-&gt;类型等替换$ 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;
    }
}