The Api spec is maintained by the Flickr, but this flickrj library kit is not maintained or supported by Flickr. Please read the attention carefully before using this library.
References
- Flickr's API documents
http://www.flickr.com/services/api/ - Flickrj web site
http://flickrj.sourceforge.net/ - Flickrj javadoc
http://flickrj.sourceforge.net/
- Get Flickr API keys to use the Flickr's API
http://www.flickr.com/services/api/keys/ - Download flickrj library and set jar file into the library directory
http://sourceforge.net/projects/flickrj/
import com.aetrion.flickr.Flickr;Sample Program
import com.aetrion.flickr.REST;
import com.aetrion.flickr.photos.SearchParameters;
import com.aetrion.flickr.photos.PhotoList;
import com.aetrion.flickr.photos.PhotosInterface;
import com.aetrion.flickr.photos.Photo;
- Search photos with tag keywords and get result
//Set api key
String key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String svr="www.flickr.com";
REST rest=new REST();
rest.setHost(svr);
//initialize Flickr object with key and rest
Flickr flickr=new Flickr(key,rest);
Flickr.debugStream=false;
//initialize SearchParameter object, this object stores the search keyword
SearchParameters searchParams=new SearchParameters();
searchParams.setSort(SearchParameters.INTERESTINGNESS_DESC);
//Create tag keyword array
String[] tags=new String[]{"Dog","Beagle"};
searchParams.setTags(tags);
//Initialize PhotosInterface object
PhotosInterface photosInterface=flickr.getPhotosInterface();
//Execute search with entered tags
PhotoList photoList=photosInterface.search(searchParams,20,1);
//get search result and fetch the photo object and get small square imag's url
if(photoList!=null){
//Get search result and check the size of photo result
for(int i=0;i<photoList.size();i++){
//get photo object
Photo photo=(Photo)photoList.get(i);
//Get small square url photo
StringBuffer strBuf=new StringBuffer();
strBuf.append("<a href=\"\">");
strBuf.append("<img border=\"0\" src=\""+photo.getSmallSquareUrl()+"\">");
strBuf.append("</a>\n");
....
}
} - Get photo and information with specified photo ID
//Set api key
String key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String svr="www.flickr.com";
REST rest=new REST();
rest.setHost(svr);
//initialize Flickr object with key and rest
Flickr flickr=new Flickr(key,rest);
Flickr.debugStream=false;
//Initialize PhotosInterface object
PhotosInterface photosInterface=flickr.getPhotosInterface();
//Execute search with photo ID you want to get information
Photo photo=photosInterface.getPhoto("[Photo ID]");
if(photo!=null){
StringBuffer strBuf=new StringBuffer();
strBuf.append("<a href=\"\">");
strBuf.append("<img border=\"0\" src=\""+photo.getThumbnailUrl()+"\">");
strBuf.append("</a>\n");
}