I'm trying to build a simple HTML document, for a class assignment, that will allow users to search flicker and display 10 results based on their search.
I've built the URL for the search and it seems to work just fine: http://api.flickr.com/services/rest/?&method=flickr.photos.search&tags=thor&api_key=b49d87bfd659c5768ab0eafa74f2b6a5&per_page=10
It requests info based on the tag "thor" and displays 10 results in xml. good so far...
Next i want to be able to store certain parts of the XML so i can use them to display the images. Based on Flickr API information I require the following... ID, farm, server, and secret.
I am using the following code to do this.
$(document).ready(function() {
$.get('api.flickr.com/services/rest/?&method=flickr.photos.search&tags=thor& api_key=b49d87bfd659c5768ab0eafa74f2b6a5&per_page=10',function(data) {
var items=[];
$.each(data.photos.photo, function(index, value) {
var ident=(value.id);
alert(ident);
});
})
});
This is not working. The biggest problem is that firebug isn't giving me any errors so I don't know where I'm going wrong. If i could just get a hand acquiring the photo ID that would be awesome. I would like to figure the rest out on my own if possible.
EDIT: I'm running this through MAMP so i'm using the url localhost/example.html
Thank you Tamil Selvan, your code allowed me to retrieve value.id. Is there a reason why when I try to retrieve any other data (value.server, value.farm, value.secret) i get a value of "undefined"?
my new code...
$(document).ready(function() {
$.get('http://api.flickr.com/services/rest/?&method=flickr.photos.search&tags=thor&api_key=b49d87bfd659c5768ab0eafa74f2b6a5&per_page=10',function(data)
{
var items=[];
$(data).find("photo").each(function(index, value) {
var ident=(value.id);
var secret_id=(value.secret);
var farm_id=(value.farm);
var server_id=(value.server);
$("#target").append("<p>"+ident+" "+server_id+" "+secret_id+" "+farm_id+"</p>");
});
});
});
Url always start with http/https
Try
$.get('http://api.flickr.com/services/rest/?&method=flickr.photos.search&tags=thor& api_key=b49d87bfd659c5768ab0eafa74f2b6a5&per_page=10',function(data) {
Edit:
$(document).ready(function() {
$.get('http://api.flickr.com/services/rest/?&method=flickr.photos.search&tags=thor& api_key=b49d87bfd659c5768ab0eafa74f2b6a5&per_page=10',function(data)
{
var items=[];
$(data).find("photo").each(function(index, value) {
var ident=(value.id);
alert(ident);
});
});
});
Edit1:
to get secret ,server, farm id from value
use
var secret_id= $(value).attr('secret');
var farm_id= $(value).attr('farm');
var server_id=$(value).attr('server');