I am trying to configure the Tumblr API on my site.
So far my text messages have worked like this:
$.ajax({ url: "http://api.tumblr.com/v2/blog/myblog.tumblr.com/posts?api_key=myapikey", dataType: 'jsonp', success: function(results){ var i = 0; while (i < 20) { var type = results.response.posts[i].type; var date = results.response.posts[i].date; if (type == "text") { var title = results.response.posts[i].title; var content = results.response.posts[i].body; $("#myDivId").append("<div class='posttitle'><h2>" + title + "</h2></div>"); $("#myDivId").append("<div class='postbody'>" + content + "</div>"); } i++; }
But I can not get the images to work. I know that for some reason, the images in the message are stored inside the array, so I thought that to get the first image, the following is enough:
else if (type == "photo") { var photourl = results.response.posts[i].photos[0].url; $("#myDivId").append("<div class='postbody'><img src='" + photourl + "'/></div>"); }
But to no avail. The docs are here if anyone is interested: http://www.tumblr.com/docs/en/api/v2#photo-posts
Does anyone know how to make these images work? Thanks
source share