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.