I'm writing a sample web based application that requires image based results to be delivered in the form of an XML document. Currently I'm using Picasa search API. I'm getting the XML response on requesting the API call URL. Here is my current implementation:
private void fetchImageURLs() {
try {
String urlString = "https://picasaweb.google.com/data/feed/api/all?";
urlString += "q="+searchTerm;
urlString += "&max-results="+numImages;
urlString += "&start-index="+offset;
// Get XML from Picasa API
URL url = new URL(urlString);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(url.openStream());
doc.getDocumentElement().normalize();
// Parse XML to obtain image URLs
NodeList nList = doc.getElementsByTagName("content");
for (int i = 0; i < nList.getLength(); i++) {
Node nNode = nList.item(i);
Element eElement = (Element) nNode;
String imageUrlString = eElement.getAttribute("src");
// Push the image URLs on the queue to be used by fetchImagesAndSave()
imageURLs.push(new URL(imageUrlString));
}
}
catch (Exception e) {
e.printStackTrace();
}
}
I would be thankful if you could help me with figuring out how to do the same using Twitter/Facebook/PhotoBucket or Flickr API. Thanks.
For Flickr:
You can use the Flickr4Java API.
But since all you need is the search you could use the REST API:
http://api.flickr.com/services/rest/?method=flickr.test.echo&name=value
The method you need is flicker.photos.search
documented here.
To use the Flickr API you need to have an API key though, so you should apply for one.