从 tumblr 的 API 获取图像、帖子标题和帖子日期
我发现 Nathan Scott 的 javascript 片段对于在静态网页上嵌入 tumblr feed 非常有用。但我也发现就我想要获得的信息而言有点太简单了。以我有限的知识,我似乎无法弄清楚如何调用帖子的标题和日期,以便我可以使用 CSS 对其进行样式设置。我还想声明,我只从常规帖子中获取第一张照片,并在 X 个字符后截断,但我没有运气。
任何形式的帮助将不胜感激!
这是 Nathan Scott 提供的原始代码!
<script type="text/javascript" src="http://collinsstreetmedia.tumblr.com/api/read/json">
</script>
<script type='text/javascript'>
$("#announcement").html(
tumblr_api_read["posts"][0]["regular-body"].substring(0,400)
);
$("#announcement_url").attr(
{
href: (tumblr_api_read["posts"][0]["url"])
}
);
</script>
I found Nathan Scott's javascript snippet for embedding a tumblr feed on a static webpage extremely useful. But I am also finding it a bit too simple in terms of the info I want to get. With my limited knowledge I cannot seem to figure out how to also call the Post's Title and the Date so that I can style it with CSS. I would also ideally like to state that I only get the first photo from the regular post and truncate after X amount of characters but I've had no luck.
Any sort of help would be greatly appreciated!
here is the original code courtesy of Nathan Scott!
<script type="text/javascript" src="http://collinsstreetmedia.tumblr.com/api/read/json">
</script>
<script type='text/javascript'>
$("#announcement").html(
tumblr_api_read["posts"][0]["regular-body"].substring(0,400)
);
$("#announcement_url").attr(
{
href: (tumblr_api_read["posts"][0]["url"])
}
);
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下操作。
您想要获取帖子的端点是这样的:
例如:
然后使用 jQuery 您可以调用该请求:
要实际解析 JSON,您可以使用简单的方法,例如:
Try the following.
The endpoint you want for fetching a post is this:
For example:
Then using jQuery you can call that request:
To actually parse JSON you can use something simple like: