diff --git a/Flickr4Java/build.gradle b/Flickr4Java/build.gradle
index 36ca6006..4e1413d6 100644
--- a/Flickr4Java/build.gradle
+++ b/Flickr4Java/build.gradle
@@ -4,7 +4,7 @@ apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'application'
-version = '2.11'
+version = '2.12'
group = 'com.flickr4java.flickr'
sourceCompatibility = '1.5'
diff --git a/Flickr4Java/pom.xml b/Flickr4Java/pom.xml
index fda52765..83d7eed4 100644
--- a/Flickr4Java/pom.xml
+++ b/Flickr4Java/pom.xml
@@ -4,7 +4,7 @@
com.flickr4java
flickr4java
- 2.12-SNAPSHOT
+ 2.13-SNAPSHOT
jar
flickr4java
Java API For Flickr. Fork of FlickrJ.
diff --git a/Flickr4Java/src/examples/java/ActivityExample.java b/Flickr4Java/src/examples/java/ActivityExample.java
index 9350cf8a..1bb9beef 100644
--- a/Flickr4Java/src/examples/java/ActivityExample.java
+++ b/Flickr4Java/src/examples/java/ActivityExample.java
@@ -12,8 +12,6 @@
import org.xml.sax.SAXException;
-import javax.xml.parsers.ParserConfigurationException;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -52,6 +50,7 @@ public ActivityExample() throws IOException {
Auth auth = new Auth();
auth.setPermission(Permission.READ);
auth.setToken(properties.getProperty("token"));
+ auth.setTokenSecret(properties.getProperty("tokensecret"));
requestContext.setAuth(auth);
Flickr.debugRequest = false;
Flickr.debugStream = false;
diff --git a/Flickr4Java/src/examples/java/UploadPhoto.java b/Flickr4Java/src/examples/java/UploadPhoto.java
index 2a2d1f57..31377618 100644
--- a/Flickr4Java/src/examples/java/UploadPhoto.java
+++ b/Flickr4Java/src/examples/java/UploadPhoto.java
@@ -6,28 +6,27 @@
import com.flickr4java.flickr.auth.Auth;
import com.flickr4java.flickr.auth.AuthInterface;
import com.flickr4java.flickr.auth.Permission;
+import com.flickr4java.flickr.people.PeopleInterface;
+import com.flickr4java.flickr.people.User;
import com.flickr4java.flickr.photos.Photo;
import com.flickr4java.flickr.photos.PhotoList;
import com.flickr4java.flickr.photos.PhotosInterface;
// import com.flickr4java.flickr.photos.Size;
import com.flickr4java.flickr.photosets.Photoset;
+import com.flickr4java.flickr.photosets.Photosets;
import com.flickr4java.flickr.photosets.PhotosetsInterface;
+// import com.flickr4java.flickr.util.IOUtilities;
+import com.flickr4java.flickr.prefs.PrefsInterface;
+// import com.flickr4java.flickr.photos.PhotosInterface;
+import com.flickr4java.flickr.uploader.UploadMetaData;
+import com.flickr4java.flickr.uploader.Uploader;
import com.flickr4java.flickr.util.AuthStore;
import com.flickr4java.flickr.util.FileAuthStore;
-import com.flickr4java.flickr.people.PeopleInterface;
-import com.flickr4java.flickr.people.User;
+import org.apache.log4j.Logger;
import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.xml.sax.SAXException;
-import org.apache.log4j.Logger;
-
-import java.text.SimpleDateFormat;
-import java.util.Set;
-
-import com.flickr4java.flickr.photosets.Photosets;
-
-
// import java.io.BufferedInputStream;
import java.io.File;
@@ -35,14 +34,15 @@
// import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.text.SimpleDateFormat;
// import java.net.URL;
import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
import java.util.Collection;
+import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Properties;
// import java.util.Map;
import java.util.Scanner;
@@ -51,27 +51,18 @@
// import java.io.FileInputStream;
// import java.io.IOException;
// import java.io.InputStream;
-
-
-// import com.flickr4java.flickr.photos.PhotosInterface;
-import com.flickr4java.flickr.uploader.UploadMetaData;
-import com.flickr4java.flickr.uploader.Uploader;
-// import com.flickr4java.flickr.util.IOUtilities;
-import com.flickr4java.flickr.prefs.PrefsInterface;
+import java.util.Set;
// import com.flickr4java.flickr.tags.Tag;
/**
- * A simple program to upload photos to a set. It checks for files already uploaded assuming the title
- * is not changed so that it can be rerun if partial upload is done.
- * It uses the tag field to store the filename as OrigFileName to be used while downloading
- * if the title has been changed.
- * If setup.properties is not available, pass the apiKey and secret as arguments to the program.
+ * A simple program to upload photos to a set. It checks for files already uploaded assuming the title is not changed so that it can be rerun if partial upload
+ * is done. It uses the tag field to store the filename as OrigFileName to be used while downloading if the title has been changed. If setup.properties is not
+ * available, pass the apiKey and secret as arguments to the program.
*
* This sample also uses the AuthStore interface, so users will only be asked to authorize on the first run.
*
- * Please NOTE that this needs Java 7 to work. Java 7 was released on July 28, 2011 and soon Java 6 may not
- * be supported anymore ( Jul 2014).
+ * Please NOTE that this needs Java 7 to work. Java 7 was released on July 28, 2011 and soon Java 6 may not be supported anymore ( Jul 2014).
*
* @author Keyur Parikh
*/
@@ -80,27 +71,33 @@ public class UploadPhoto {
private static final Logger logger = Logger.getLogger(UploadPhoto.class);
- private String nsid;
- private String username;
+ private String nsid;
+
+ private String username;
// private final String sharedSecret;
private final Flickr flickr;
private AuthStore authStore;
- public boolean flickrDebug = false;
- private boolean setOrigFilenameTag = true;
+
+ public boolean flickrDebug = false;
+
+ private boolean setOrigFilenameTag = true;
+
private boolean replaceSpaces = false;
- private int privacy = -1;
+ private int privacy = -1;
HashMap allSetsMap = new HashMap();
+
HashMap> setNameToId = new HashMap>();
+
public static final SimpleDateFormat smp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss a");
public UploadPhoto(String apiKey, String nsid, String sharedSecret, File authsDir, String username) throws FlickrException {
flickr = new Flickr(apiKey, sharedSecret, new REST());
-
+
this.username = username;
this.nsid = nsid;
// this.sharedSecret = sharedSecret;
@@ -108,79 +105,79 @@ public UploadPhoto(String apiKey, String nsid, String sharedSecret, File authsDi
if (authsDir != null) {
this.authStore = new FileAuthStore(authsDir);
}
-
+
// If one of them is not filled in, find and populate it.
- if(username == null || username.equals(""))
- setUserName();
- if(nsid == null || nsid.equals(""))
- setNsid();
+ if (username == null || username.equals(""))
+ setUserName();
+ if (nsid == null || nsid.equals(""))
+ setNsid();
- }
+ }
private void setUserName() throws FlickrException {
- if(nsid != null && !nsid.equals("")) {
- Auth auth = null;
- if (authStore != null) {
- auth = authStore.retrieve(nsid);
- if (auth != null) {
- username = auth.getUser().getUsername();
- }
- }
- // For this to work: REST.java or PeopleInterface needs to change to pass apiKey
- // as the parameter to the call which is not authenticated.
-
- if(auth == null) {
- // Get nsid using flickr.people.findByUsername
- PeopleInterface peopleInterf = flickr.getPeopleInterface();
- User u = peopleInterf.getInfo(nsid);
- if(u != null) {
- username = u.getUsername();
- }
- }
- }
- }
+ if (nsid != null && !nsid.equals("")) {
+ Auth auth = null;
+ if (authStore != null) {
+ auth = authStore.retrieve(nsid);
+ if (auth != null) {
+ username = auth.getUser().getUsername();
+ }
+ }
+ // For this to work: REST.java or PeopleInterface needs to change to pass apiKey
+ // as the parameter to the call which is not authenticated.
+
+ if (auth == null) {
+ // Get nsid using flickr.people.findByUsername
+ PeopleInterface peopleInterf = flickr.getPeopleInterface();
+ User u = peopleInterf.getInfo(nsid);
+ if (u != null) {
+ username = u.getUsername();
+ }
+ }
+ }
+ }
+
/**
- * Check local saved copy first ??.
- * If Auth by username is available, then we will not need to make the API call.
+ * Check local saved copy first ??. If Auth by username is available, then we will not need to make the API call.
*
* @throws FlickrException
*/
- private void setNsid() throws FlickrException {
-
- if(username != null && !username.equals("")) {
- Auth auth = null;
- if (authStore != null) {
- auth = authStore.retrieve(username); // assuming FileAuthStore is enhanced else need to
- // keep in user-level files.
-
- if (auth != null) {
- nsid = auth.getUser().getId();
- }
- }
- if(auth != null)
- return;
-
- Auth[] allAuths = authStore.retrieveAll();
- for(int i = 0 ; i < allAuths.length; i++) {
- if(username.equals(allAuths[i].getUser().getUsername())) {
- nsid = allAuths[i].getUser().getId();
- return;
- }
- }
-
- // For this to work: REST.java or PeopleInterface needs to change to pass apiKey
- // as the parameter to the call which is not authenticated.
-
- // Get nsid using flickr.people.findByUsername
- PeopleInterface peopleInterf = flickr.getPeopleInterface();
- User u = peopleInterf.findByUsername(username);
- if(u != null) {
- nsid = u.getId();
- }
- }
- }
-
+ private void setNsid() throws FlickrException {
+
+ if (username != null && !username.equals("")) {
+ Auth auth = null;
+ if (authStore != null) {
+ auth = authStore.retrieve(username); // assuming FileAuthStore is enhanced else need to
+ // keep in user-level files.
+
+ if (auth != null) {
+ nsid = auth.getUser().getId();
+ }
+ }
+ if (auth != null)
+ return;
+
+ Auth[] allAuths = authStore.retrieveAll();
+ for (int i = 0; i < allAuths.length; i++) {
+ if (username.equals(allAuths[i].getUser().getUsername())) {
+ nsid = allAuths[i].getUser().getId();
+ return;
+ }
+ }
+
+ // For this to work: REST.java or PeopleInterface needs to change to pass apiKey
+ // as the parameter to the call which is not authenticated.
+
+ // Get nsid using flickr.people.findByUsername
+ PeopleInterface peopleInterf = flickr.getPeopleInterface();
+ User u = peopleInterf.findByUsername(username);
+ if (u != null) {
+ nsid = u.getId();
+ }
+ }
+ }
+
private void authorize() throws IOException, SAXException, FlickrException {
AuthInterface authInterface = flickr.getAuthInterface();
Token accessToken = authInterface.getRequestToken();
@@ -201,31 +198,32 @@ private void authorize() throws IOException, SAXException, FlickrException {
RequestContext.getRequestContext().setAuth(auth);
this.authStore.store(auth);
scanner.close();
- System.out.println("Thanks. You probably will not have to do this every time. Auth saved for user: "
- + auth.getUser().getUsername() + " nsid is: " + auth.getUser().getId());
+ System.out.println("Thanks. You probably will not have to do this every time. Auth saved for user: " + auth.getUser().getUsername() + " nsid is: "
+ + auth.getUser().getId());
System.out.println(" AuthToken: " + auth.getToken() + " tokenSecret: " + auth.getTokenSecret());
}
-/**
- * If the Authtoken was already created in a separate program but not saved to file.
- *
- * @param authToken
- * @param tokenSecret
- * @param username
- * @return
- * @throws IOException
- */
+
+ /**
+ * If the Authtoken was already created in a separate program but not saved to file.
+ *
+ * @param authToken
+ * @param tokenSecret
+ * @param username
+ * @return
+ * @throws IOException
+ */
private Auth constructAuth(String authToken, String tokenSecret, String username) throws IOException {
-
+
Auth auth = new Auth();
auth.setToken(authToken);
auth.setTokenSecret(tokenSecret);
-
+
// Prompt to ask what permission is needed: read, update or delete.
- auth.setPermission(Permission.fromString("delete") );
+ auth.setPermission(Permission.fromString("delete"));
User user = new User();
// Later change the following 3. Either ask user to pass on command line or read
- // from saved file.
+ // from saved file.
user.setId(nsid);
user.setUsername((username));
user.setRealName("");
@@ -237,32 +235,31 @@ private Auth constructAuth(String authToken, String tokenSecret, String username
public void setAuth(String authToken, String username, String tokenSecret) throws IOException, SAXException, FlickrException {
RequestContext rc = RequestContext.getRequestContext();
Auth auth = null;
-
- if(authToken != null && !authToken.equals("") && tokenSecret != null && !tokenSecret.equals("")) {
- auth = constructAuth(authToken, tokenSecret, username);
- rc.setAuth(auth);
- }
- else {
- if (this.authStore != null) {
- auth = this.authStore.retrieve(this.nsid);
- if (auth == null) {
- this.authorize();
- } else {
- rc.setAuth(auth);
- }
- }
+
+ if (authToken != null && !authToken.equals("") && tokenSecret != null && !tokenSecret.equals("")) {
+ auth = constructAuth(authToken, tokenSecret, username);
+ rc.setAuth(auth);
+ } else {
+ if (this.authStore != null) {
+ auth = this.authStore.retrieve(this.nsid);
+ if (auth == null) {
+ this.authorize();
+ } else {
+ rc.setAuth(auth);
+ }
+ }
}
}
public int getPrivacy() throws Exception {
- PrefsInterface prefi = flickr.getPrefsInterface();
- privacy = prefi.getPrivacy();
+ PrefsInterface prefi = flickr.getPrefsInterface();
+ privacy = prefi.getPrivacy();
- return(privacy);
+ return (privacy);
}
- private String makeSafeFilename(String input) {
+ private String makeSafeFilename(String input) {
byte[] fname = input.getBytes();
byte[] bad = new byte[] { '\\', '/', '"', '*' };
byte replace = '_';
@@ -272,16 +269,16 @@ private String makeSafeFilename(String input) {
fname[i] = replace;
}
}
- if(replaceSpaces && fname[i] == ' ')
- fname[i] = '_';
+ if (replaceSpaces && fname[i] == ' ')
+ fname[i] = '_';
}
return new String(fname);
}
public String uploadfile(String filename, String inpTitle) throws Exception {
- String photoId;
+ String photoId;
- RequestContext rc = RequestContext.getRequestContext();
+ RequestContext rc = RequestContext.getRequestContext();
if (this.authStore != null) {
Auth auth = this.authStore.retrieve(this.nsid);
@@ -292,104 +289,90 @@ public String uploadfile(String filename, String inpTitle) throws Exception {
}
}
- //PhotosetsInterface pi = flickr.getPhotosetsInterface();
+ // PhotosetsInterface pi = flickr.getPhotosetsInterface();
// PhotosInterface photoInt = flickr.getPhotosInterface();
// Map allPhotos = new HashMap();
-/**
-
- 1 : Public
- 2 : Friends only
- 3 : Family only
- 4 : Friends and Family
- 5 : Private
-
-**/
- if( privacy == -1)
- getPrivacy();
-
- UploadMetaData metaData = new UploadMetaData();
-
- if(privacy == 1)
- metaData.setPublicFlag(true);
- if(privacy == 2 || privacy == 4)
- metaData.setFriendFlag(true);
- if(privacy == 3 || privacy == 4)
- metaData.setFamilyFlag(true);
-
- if(basefilename == null || basefilename.equals(""))
- basefilename = filename; // "image.jpg";
-
- String title = basefilename;
- boolean setMimeType = true; // change during testing. Doesn't seem to be supported at this time in flickr.
- if(setMimeType) {
- if(basefilename.lastIndexOf('.') > 0) {
- title = basefilename.substring(0, basefilename.lastIndexOf('.') );
- String suffix = basefilename.substring(basefilename.lastIndexOf('.')+1);
- // Set Mime Type if known.
-
- // Later use a mime-type properties file or a hash table of all known photo and video types
- // allowed by flickr.
-
- if(suffix.equalsIgnoreCase("png")) {
- metaData.setFilemimetype("image/png");
- }
- else if(suffix.equalsIgnoreCase("mpg") ||suffix.equalsIgnoreCase("mpeg") ) {
- metaData.setFilemimetype("video/mpeg");
- }
- else if(suffix.equalsIgnoreCase("mov")) {
- metaData.setFilemimetype("video/quicktime");
- }
- }
- }
- logger.debug(" File : " + filename );
- logger.debug(" basefilename : " + basefilename );
-
- if(inpTitle != null && !inpTitle.equals("")) {
- title = inpTitle;
- logger.debug(" title : " + inpTitle );
- metaData.setTitle(title);
- } // flickr defaults the title field from file name.
-
- // UploadMeta is using String not Tag class.
-
- // Tags are getting mangled by yahoo stripping off the = , '.' and many other punctuation characters
- // and converting to lower case: use the raw tag field to find the real value for checking and
- // for download.
- if(setOrigFilenameTag) {
- List tags = new ArrayList();
- String tmp = basefilename;
- basefilename = makeSafeFilename(basefilename);
- tags.add("OrigFileName='" + basefilename + "'");
- metaData.setTags(tags);
-
- if(!tmp.equals(basefilename)){
- System.out.println(" File : " + basefilename + " contains special characters. stored as " + basefilename + " in tag field" );
- }
- }
+ /**
+ * 1 : Public 2 : Friends only 3 : Family only 4 : Friends and Family 5 : Private
+ **/
+ if (privacy == -1)
+ getPrivacy();
+
+ UploadMetaData metaData = new UploadMetaData();
+
+ if (privacy == 1)
+ metaData.setPublicFlag(true);
+ if (privacy == 2 || privacy == 4)
+ metaData.setFriendFlag(true);
+ if (privacy == 3 || privacy == 4)
+ metaData.setFamilyFlag(true);
+
+ if (basefilename == null || basefilename.equals(""))
+ basefilename = filename; // "image.jpg";
+
+ String title = basefilename;
+ boolean setMimeType = true; // change during testing. Doesn't seem to be supported at this time in flickr.
+ if (setMimeType) {
+ if (basefilename.lastIndexOf('.') > 0) {
+ title = basefilename.substring(0, basefilename.lastIndexOf('.'));
+ String suffix = basefilename.substring(basefilename.lastIndexOf('.') + 1);
+ // Set Mime Type if known.
+
+ // Later use a mime-type properties file or a hash table of all known photo and video types
+ // allowed by flickr.
+
+ if (suffix.equalsIgnoreCase("png")) {
+ metaData.setFilemimetype("image/png");
+ } else if (suffix.equalsIgnoreCase("mpg") || suffix.equalsIgnoreCase("mpeg")) {
+ metaData.setFilemimetype("video/mpeg");
+ } else if (suffix.equalsIgnoreCase("mov")) {
+ metaData.setFilemimetype("video/quicktime");
+ }
+ }
+ }
+ logger.debug(" File : " + filename);
+ logger.debug(" basefilename : " + basefilename);
+
+ if (inpTitle != null && !inpTitle.equals("")) {
+ title = inpTitle;
+ logger.debug(" title : " + inpTitle);
+ metaData.setTitle(title);
+ } // flickr defaults the title field from file name.
+
+ // UploadMeta is using String not Tag class.
+
+ // Tags are getting mangled by yahoo stripping off the = , '.' and many other punctuation characters
+ // and converting to lower case: use the raw tag field to find the real value for checking and
+ // for download.
+ if (setOrigFilenameTag) {
+ List tags = new ArrayList();
+ String tmp = basefilename;
+ basefilename = makeSafeFilename(basefilename);
+ tags.add("OrigFileName='" + basefilename + "'");
+ metaData.setTags(tags);
+
+ if (!tmp.equals(basefilename)) {
+ System.out.println(" File : " + basefilename + " contains special characters. stored as " + basefilename + " in tag field");
+ }
+ }
// File imageFile = new File(filename);
// InputStream in = null;
Uploader uploader = flickr.getUploader();
- // ByteArrayOutputStream out = null;
+ // ByteArrayOutputStream out = null;
try {
// in = new FileInputStream(imageFile);
// out = new ByteArrayOutputStream();
-
+
// int b = -1;
- /**
- while ((b = in.read()) != -1) {
- out.write((byte) b);
- }
- **/
+ /**
+ * while ((b = in.read()) != -1) { out.write((byte) b); }
+ **/
- /**
- byte[] buf = new byte[1024];
- while ((b = in.read(buf)) != -1) {
- // fos.write(read);
- out.write(buf, 0, b);
- }
- **/
+ /**
+ * byte[] buf = new byte[1024]; while ((b = in.read(buf)) != -1) { // fos.write(read); out.write(buf, 0, b); }
+ **/
metaData.setFilename(basefilename);
// check correct handling of escaped value
@@ -399,93 +382,97 @@ else if(suffix.equalsIgnoreCase("mov")) {
logger.debug(" File : " + filename + " uploaded: photoId = " + photoId);
} finally {
-
+
}
- return(photoId);
+ return (photoId);
}
public void getPhotosetsInfo() {
-
+
PhotosetsInterface pi = flickr.getPhotosetsInterface();
try {
- int setsPage = 1;
- while (true) {
- Photosets photosets = pi.getList(nsid, 500, setsPage);
- Collection setsColl = photosets.getPhotosets();
- Iterator setsIter = setsColl.iterator();
- while (setsIter.hasNext()) {
- Photoset set = setsIter.next();
- allSetsMap.put(set.getId(), set);
-
- // 2 or more sets can in theory have the same name. !!!
- ArrayList setIdarr = setNameToId.get(set.getTitle());
- if(setIdarr == null) {
- setIdarr = new ArrayList();
- setIdarr.add(new String(set.getId()));
- setNameToId.put(set.getTitle(), setIdarr);
- }
- else {
- setIdarr.add(new String(set.getId()));
- }
- }
-
- if (setsColl.size() < 500) {
- break;
- }
- setsPage++;
- }
- logger.debug(" Sets retrieved: " + allSetsMap.size());
- // all_sets_retrieved = true;
- // Print dups if any.
-
- Set keys = setNameToId.keySet();
- Iterator iter = keys.iterator();
- while(iter.hasNext()) {
- String name = iter.next();
- ArrayList setIdarr = setNameToId.get(name);
- if(setIdarr != null && setIdarr.size() > 1) {
- System.out.println("There is more than 1 set with this name : " + setNameToId.get(name));
- for(int j = 0; j < setIdarr.size(); j++) {
- System.out.println(" id: " + setIdarr.get(j));
- }
- }
- }
+ int setsPage = 1;
+ while (true) {
+ Photosets photosets = pi.getList(nsid, 500, setsPage, null);
+ Collection setsColl = photosets.getPhotosets();
+ Iterator setsIter = setsColl.iterator();
+ while (setsIter.hasNext()) {
+ Photoset set = setsIter.next();
+ allSetsMap.put(set.getId(), set);
+
+ // 2 or more sets can in theory have the same name. !!!
+ ArrayList setIdarr = setNameToId.get(set.getTitle());
+ if (setIdarr == null) {
+ setIdarr = new ArrayList();
+ setIdarr.add(new String(set.getId()));
+ setNameToId.put(set.getTitle(), setIdarr);
+ } else {
+ setIdarr.add(new String(set.getId()));
+ }
+ }
+
+ if (setsColl.size() < 500) {
+ break;
+ }
+ setsPage++;
+ }
+ logger.debug(" Sets retrieved: " + allSetsMap.size());
+ // all_sets_retrieved = true;
+ // Print dups if any.
+
+ Set keys = setNameToId.keySet();
+ Iterator iter = keys.iterator();
+ while (iter.hasNext()) {
+ String name = iter.next();
+ ArrayList setIdarr = setNameToId.get(name);
+ if (setIdarr != null && setIdarr.size() > 1) {
+ System.out.println("There is more than 1 set with this name : " + setNameToId.get(name));
+ for (int j = 0; j < setIdarr.size(); j++) {
+ System.out.println(" id: " + setIdarr.get(j));
+ }
+ }
+ }
} catch (FlickrException e) {
- e.printStackTrace();
+ e.printStackTrace();
}
}
private String setid = null;
+
private String basefilename = null;
- private PhotoList photos = new PhotoList();
- private HashMap filePhotos = new HashMap();
- private static void Usage() {
+ private final PhotoList photos = new PhotoList();
+
+ private final HashMap filePhotos = new HashMap();
+
+ private static void Usage() {
System.out.println("Usage: java " + UploadPhoto.class.getName() + " [ -n nsid | -u username ] -s setName { File../Directories}");
System.out.println(" Must pass either -u username or -n nsid ");
System.out.println(" Must pass -s followed by set-name(albums) followed by file/directories.");
- System.out.println("apiKey and shared secret must be available as apiKey and secret via setup.properties or passed as -apiKey key -secret shared-secret");
- System.exit(1);
- }
+ System.out
+ .println("apiKey and shared secret must be available as apiKey and secret via setup.properties or passed as -apiKey key -secret shared-secret");
+ System.exit(1);
+ }
+
+ /**
+ * @return the setOrigFilenameTag
+ */
+ public boolean isSetorigfilenametag() {
+ return setOrigFilenameTag;
+ }
/**
- * @return the setOrigFilenameTag
- */
- public boolean isSetorigfilenametag() {
- return setOrigFilenameTag;
- }
-
- /**
- * @param setOrigFilenameTag the setOrigFilenameTag to set
- */
- public void setSetorigfilenametag(boolean setOrigFilenameTag) {
- this.setOrigFilenameTag = setOrigFilenameTag;
- }
-
- public static void main(String[] args) throws Exception {
-
+ * @param setOrigFilenameTag
+ * the setOrigFilenameTag to set
+ */
+ public void setSetorigfilenametag(boolean setOrigFilenameTag) {
+ this.setOrigFilenameTag = setOrigFilenameTag;
+ }
+
+ public static void main(String[] args) throws Exception {
+
String apiKey = null; // args[0];
String sharedSecret = null; // args[1];
@@ -493,379 +480,372 @@ public static void main(String[] args) throws Exception {
InputStream in = null;
try {
in = UploadPhoto.class.getResourceAsStream("/setup.properties");
- if(in != null) {
- properties.load(in);
- apiKey = properties.getProperty("apiKey");
- sharedSecret = properties.getProperty("secret");
- if(apiKey != null && sharedSecret != null)
- logger.debug("Found setup.properties in classpath and set apiKey and shared secret");
+ if (in != null) {
+ properties.load(in);
+ apiKey = properties.getProperty("apiKey");
+ sharedSecret = properties.getProperty("secret");
+ if (apiKey != null && sharedSecret != null)
+ logger.debug("Found setup.properties in classpath and set apiKey and shared secret");
}
} catch (Exception e) {
- e.printStackTrace();
- }
- finally {
- if(in != null)
- in.close();
+ e.printStackTrace();
+ } finally {
+ if (in != null)
+ in.close();
}
if (args.length < 5) {
- Usage();
- System.exit(1);
- }
-
- ArrayList uploadfileArgs = new ArrayList();
- ArrayList optionArgs = new ArrayList();
+ Usage();
+ System.exit(1);
+ }
+
+ ArrayList uploadfileArgs = new ArrayList();
+ ArrayList optionArgs = new ArrayList();
- // Flickr.debugRequest = true; // keep it false else entire file will be in stdout.
+ // Flickr.debugRequest = true; // keep it false else entire file will be in stdout.
- // Flickr.debugStream = true;
+ // Flickr.debugStream = true;
- String authsDirStr = System.getProperty("user.home") + File.separatorChar + ".flickrAuth";
+ String authsDirStr = System.getProperty("user.home") + File.separatorChar + ".flickrAuth";
String nsid = null;
String username = null;
String accessToken = null; // Optional entry.
- String tokenSecret = null; // Optional entry.
- String setName = null;
-
- boolean settagname = true; // Default to true to add tag while uploading.
-
+ String tokenSecret = null; // Optional entry.
+ String setName = null;
+
+ boolean settagname = true; // Default to true to add tag while uploading.
int i = 0;
/***
- for(i = 0; i < args.length; i++) {
- System.out.println("args[" + i + "] " + args[i]);
+ * for(i = 0; i < args.length; i++) { System.out.println("args[" + i + "] " + args[i]); }
+ **/
+
+ for (i = 0; i < args.length; i++) {
+ switch (args[i]) {
+ case "-n":
+ if (i < args.length)
+ nsid = args[++i];
+ break;
+ case "-u":
+ if (i < args.length)
+ username = args[++i];
+ break;
+ case "-apiKey":
+ if (i < args.length)
+ apiKey = args[++i];
+ break;
+
+ case "-secret":
+ if (i < args.length)
+ sharedSecret = args[++i];
+ break;
+ case "-notags":
+ if (i < args.length)
+ settagname = false;
+ break;
+
+ case "-a":
+ if (i < args.length)
+ accessToken = args[++i];
+ break;
+ case "-t":
+ if (i < args.length)
+ tokenSecret = args[++i];
+ break;
+ case "-s":
+ if (i < args.length)
+ setName = args[++i];
+ break;
+ case "-option":
+ if (i < args.length)
+ optionArgs.add(args[++i]);
+ break;
+ default:
+ if (setName != null)
+ uploadfileArgs.add(args[i]);
+ else {
+ Usage();
+ System.exit(1);
+ }
+ }
+ }
+
+ if (apiKey == null || sharedSecret == null || (username == null && nsid == null) || (setName == null) || (uploadfileArgs.size() == 0)) {
+ Usage();
+ System.exit(1);
}
- **/
-
- for(i = 0; i < args.length; i++) {
- switch(args[i]) {
- case "-n": if(i < args.length)
- nsid = args[++i];
- break;
- case "-u": if(i < args.length)
- username = args[++i];
- break;
- case "-apiKey": if(i < args.length)
- apiKey = args[++i];
- break;
-
- case "-secret": if(i < args.length)
- sharedSecret = args[++i];
- break;
- case "-notags" : if(i < args.length)
- settagname = false;
- break;
-
- case "-a" : if(i < args.length)
- accessToken = args[++i];
- break;
- case "-t" : if(i < args.length)
- tokenSecret = args[++i];
- break;
- case "-s" : if(i < args.length)
- setName = args[++i];
- break;
- case "-option":
- if(i < args.length)
- optionArgs.add(args[++i]);
- break;
- default : if(setName != null)
- uploadfileArgs.add(args[i]);
- else {
- Usage();
- System.exit(1);
- }
- }
+
+ UploadPhoto bf = new UploadPhoto(apiKey, nsid, sharedSecret, new File(authsDirStr), username);
+ for (i = 0; i < optionArgs.size(); i++) {
+ bf.addOption(optionArgs.get(i));
}
-
- if(apiKey == null || sharedSecret == null ||
- (username == null && nsid == null) || (setName == null ) ||
- (uploadfileArgs.size() == 0) ) {
- Usage();
- System.exit(1);
+ bf.setSetorigfilenametag(settagname);
+ bf.setAuth(accessToken, username, tokenSecret);
+
+ if (!bf.canUpload())
+ System.exit(1);
+
+ bf.getPrivacy();
+
+ bf.getPhotosetsInfo();
+
+ if (setName != null && !setName.equals("")) {
+
+ bf.getSetPhotos(setName);
}
-
- UploadPhoto bf = new UploadPhoto(apiKey, nsid, sharedSecret, new File(authsDirStr), username);
- for(i = 0; i < optionArgs.size(); i++) {
- bf.addOption( optionArgs.get(i));
+
+ // String photoid;
+
+ for (i = 0; i < uploadfileArgs.size(); i++) {
+ String filename = uploadfileArgs.get(i);
+
+ File f = new File(filename);
+ if (f.isDirectory()) {
+ String[] filelist = f.list(new UploadFilenameFilter());
+ logger.debug("Processing directory : " + uploadfileArgs.get(i));
+ for (int j = 0; j < filelist.length; j++) {
+ bf.processFileArg(uploadfileArgs.get(i) + File.separatorChar + filelist[j], setName);
+ }
+ } else {
+ bf.processFileArg(filename, setName);
+ }
}
- bf.setSetorigfilenametag(settagname);
- bf.setAuth(accessToken, username, tokenSecret );
-
- if(!bf.canUpload())
- System.exit(1);
-
- bf.getPrivacy();
-
- bf.getPhotosetsInfo();
-
- if(setName != null && !setName.equals("")) {
-
- bf.getSetPhotos(setName);
- }
-
- // String photoid;
-
- for( i = 0; i < uploadfileArgs.size(); i++) {
- String filename = uploadfileArgs.get(i);
-
- File f = new File(filename);
- if(f.isDirectory()) {
- String[] filelist = f.list(new UploadFilenameFilter());
- logger.debug("Processing directory : " + uploadfileArgs.get(i) );
- for(int j = 0; j < filelist.length; j++) {
- bf.processFileArg( uploadfileArgs.get(i) + File.separatorChar + filelist[j], setName);
- }
- }
- else {
- bf.processFileArg( filename, setName);
- }
- }
}
-
- private static final String[] photoSuffixes = {
- "jpg"
- ,"jpeg"
- ,"png"
- ,"gif"
- ,"bmp"
- ,"tif","tiff" };
-
- private static final String[] videoSuffixes = {
- "3gp","3gp","avi","mov","mp4","mpg","mpeg","wmv","ogg","ogv","m2v"};
-
+
+ private static final String[] photoSuffixes = { "jpg", "jpeg", "png", "gif", "bmp", "tif", "tiff" };
+
+ private static final String[] videoSuffixes = { "3gp", "3gp", "avi", "mov", "mp4", "mpg", "mpeg", "wmv", "ogg", "ogv", "m2v" };
+
static class UploadFilenameFilter implements FilenameFilter {
-
- // Following suffixes from flickr upload page. An App should have this configurable,
- // for videos and photos separately.
+ // Following suffixes from flickr upload page. An App should have this configurable,
+ // for videos and photos separately.
+
+ @Override
public boolean accept(File dir, String name) {
- if(isValidSuffix(name))
- return true;
- else
- return false;
+ if (isValidSuffix(name))
+ return true;
+ else
+ return false;
}
}
private static boolean isValidSuffix(String basefilename) {
- if(basefilename.lastIndexOf('.') <= 0) {
- return false;
- }
- String suffix = basefilename.substring(basefilename.lastIndexOf('.')+1).toLowerCase();
- for(int i = 0; i < photoSuffixes.length; i++) {
- if(photoSuffixes[i].equals(suffix))
- return true;
- }
- for(int i = 0; i < videoSuffixes.length; i++) {
- if(videoSuffixes[i].equals(suffix))
- return true;
- }
- logger.debug(basefilename + " does not have a valid suffix, skipped.");
- return false;
+ if (basefilename.lastIndexOf('.') <= 0) {
+ return false;
+ }
+ String suffix = basefilename.substring(basefilename.lastIndexOf('.') + 1).toLowerCase();
+ for (int i = 0; i < photoSuffixes.length; i++) {
+ if (photoSuffixes[i].equals(suffix))
+ return true;
+ }
+ for (int i = 0; i < videoSuffixes.length; i++) {
+ if (videoSuffixes[i].equals(suffix))
+ return true;
+ }
+ logger.debug(basefilename + " does not have a valid suffix, skipped.");
+ return false;
}
-
+
private void processFileArg(String filename, String setName) throws Exception {
- String photoid;
- if(filename.equals("")) {
- System.out.println("filename must be entered for uploadfile " );
- return;
- }
- if(filename.lastIndexOf(File.separatorChar ) > 0)
- basefilename = filename.substring(filename.lastIndexOf(File.separatorChar ) + 1, filename.length());
- else
- basefilename = filename;
-
- boolean fileUploaded = checkIfLoaded(filename);
-
- if(! fileUploaded) {
- if(!isValidSuffix(basefilename)) {
- System.out.println(" File: " + basefilename + " is not a supported filetype for flickr (invalid suffix)");
- return;
- }
-
- File f = new File(filename);
- if(!f.exists() || !f.canRead()) {
- System.out.println(" File: " + filename + " cannot be processed, does not exist or is unreadable.");
- return;
- }
- logger.debug("Calling uploadfile for filename : " + filename );
- logger.info("Upload of " + filename + " started at: " + smp.format(new Date()) + "\n");
-
- photoid = uploadfile(filename, null);
- // Add to Set. Create set if it does not exist.
- if(photoid != null) {
- addPhotoToSet( photoid, setName);
- }
- logger.info("Upload of " + filename + " finished at: " + smp.format(new Date()) + "\n");
-
- } else {
- logger.info(" File: " + filename + " has already been loaded on " + getUploadedTime(filename) );
- }
+ String photoid;
+ if (filename.equals("")) {
+ System.out.println("filename must be entered for uploadfile ");
+ return;
+ }
+ if (filename.lastIndexOf(File.separatorChar) > 0)
+ basefilename = filename.substring(filename.lastIndexOf(File.separatorChar) + 1, filename.length());
+ else
+ basefilename = filename;
+
+ boolean fileUploaded = checkIfLoaded(filename);
+
+ if (!fileUploaded) {
+ if (!isValidSuffix(basefilename)) {
+ System.out.println(" File: " + basefilename + " is not a supported filetype for flickr (invalid suffix)");
+ return;
+ }
+
+ File f = new File(filename);
+ if (!f.exists() || !f.canRead()) {
+ System.out.println(" File: " + filename + " cannot be processed, does not exist or is unreadable.");
+ return;
+ }
+ logger.debug("Calling uploadfile for filename : " + filename);
+ logger.info("Upload of " + filename + " started at: " + smp.format(new Date()) + "\n");
+
+ photoid = uploadfile(filename, null);
+ // Add to Set. Create set if it does not exist.
+ if (photoid != null) {
+ addPhotoToSet(photoid, setName);
+ }
+ logger.info("Upload of " + filename + " finished at: " + smp.format(new Date()) + "\n");
+
+ } else {
+ logger.info(" File: " + filename + " has already been loaded on " + getUploadedTime(filename));
+ }
}
- private void addOption(String opt) {
+ private void addOption(String opt) {
- switch(opt) {
- case "replaceSpaces": replaceSpaces = true;
- break;
+ switch (opt) {
+ case "replaceSpaces":
+ replaceSpaces = true;
+ break;
- case "notags": setSetorigfilenametag(false);
- break;
-
-
- default: // Not supported at this time.
- System.out.println("Option: " + opt + " is not supported at this time");
- }
- }
+ case "notags":
+ setSetorigfilenametag(false);
+ break;
+
+ default: // Not supported at this time.
+ System.out.println("Option: " + opt + " is not supported at this time");
+ }
+ }
-
private boolean canUpload() {
- RequestContext rc = RequestContext.getRequestContext();
- Auth auth = null;
- auth = rc.getAuth();
- if(auth == null) {
- System.out.println(" Cannot upload, there is no authorization information.");
- return false;
- }
- Permission perm = auth.getPermission();
- if( (perm.getType() == Permission.WRITE_TYPE) || (perm.getType() == Permission.DELETE_TYPE))
- return true;
- else {
- System.out.println(" Cannot upload, You need write or delete permission, you have : " + perm.toString());
- return false;
- }
+ RequestContext rc = RequestContext.getRequestContext();
+ Auth auth = null;
+ auth = rc.getAuth();
+ if (auth == null) {
+ System.out.println(" Cannot upload, there is no authorization information.");
+ return false;
+ }
+ Permission perm = auth.getPermission();
+ if ((perm.getType() == Permission.WRITE_TYPE) || (perm.getType() == Permission.DELETE_TYPE))
+ return true;
+ else {
+ System.out.println(" Cannot upload, You need write or delete permission, you have : " + perm.toString());
+ return false;
+ }
}
-/**
- * The assumption here is that for a given set only unique file-names will be loaded and the title
- * field can be used. Later change to use the tags field ( OrigFileName) and strip off the suffix.
- *
- * @param filename
- * @return
- */
- private boolean checkIfLoaded(String filename) {
-
- String title;
- if(basefilename.lastIndexOf('.') > 0)
- title = basefilename.substring(0, basefilename.lastIndexOf('.') );
- else
- return false;
-
- if(filePhotos.containsKey(title))
- return true;
-
- return false;
- }
-
- private String getUploadedTime(String filename) {
-
- String title = "";
- if(basefilename.lastIndexOf('.') > 0)
- title = basefilename.substring(0, basefilename.lastIndexOf('.') );
-
- if(filePhotos.containsKey(title)) {
- Photo p = filePhotos.get(title);
- if(p.getDatePosted() != null) {
- return(smp.format(p.getDatePosted()));
- }
- }
-
- return "";
- }
-
- private void getSetPhotos(String setName) throws FlickrException {
- // Check if this is an existing set. If it is get all the photo list to avoid reloading already
- // loaded photos.
- ArrayList setIdarr ;
- setIdarr = setNameToId.get(setName);
- if(setIdarr != null) {
- setid = setIdarr.get(0);
- PhotosetsInterface pi = flickr.getPhotosetsInterface();
-
- Set extras = new HashSet();
- /**
- * A comma-delimited list of extra information to fetch for each returned record.
- * Currently supported fields are: license, date_upload, date_taken, owner_name,
- * icon_server, original_format, last_update, geo, tags, machine_tags, o_dims,
- * views, media, path_alias, url_sq, url_t, url_s, url_m, url_o
- */
-
- extras.add("date_upload");
- extras.add("original_format");
- extras.add("media");
- // extras.add("url_o");
- extras.add("tags");
-
- int setPage = 1;
- while (true) {
- PhotoList tmpSet = pi.getPhotos(setid, extras, Flickr.PRIVACY_LEVEL_NO_FILTER, 500, setPage);
-
- int tmpSetSize = tmpSet.size();
- photos.addAll(tmpSet);
- if (tmpSetSize < 500) {
- break;
- }
- setPage++;
- }
- for(int i = 0; i < photos.size(); i++) {
- filePhotos.put(photos.get(i).getTitle(), photos.get(i));
- }
- if(flickrDebug) {
- logger.debug("Set title: " + setName + " id: " + setid + " found");
- logger.debug(" Photos in Set already loaded: " + photos.size() );
- }
- }
- }
-
- public void addPhotoToSet(String photoid, String setName) throws Exception {
-
- ArrayList setIdarr ;
-
- // all_set_maps.
-
- PhotosetsInterface psetsInterface = flickr.getPhotosetsInterface();
-
- Photoset set = null;
-
- if(setid == null) {
- // In case it is a new photo-set.
- setIdarr = setNameToId.get(setName);
- if(setIdarr == null) {
- // setIdarr should be null since we checked it getSetPhotos.
- // Create the new set.
- // set the setid .
-
- String description = "";
- set = psetsInterface.create(setName, description, photoid);
- setid = set.getId();
-
- setIdarr = new ArrayList();
- setIdarr.add(new String(setid));
- setNameToId.put(setName, setIdarr);
-
- allSetsMap.put(set.getId(), set);
- }
- }
- else {
- set = allSetsMap.get(setid);
- psetsInterface.addPhoto(setid , photoid);
- }
- // Add to photos .
-
- // Add Photo to existing set.
- PhotosInterface photoInt = flickr.getPhotosInterface();
- Photo p = photoInt.getPhoto(photoid);
- if(p != null) {
- photos.add(p);
- String title;
- if(basefilename.lastIndexOf('.') > 0)
- title = basefilename.substring(0, basefilename.lastIndexOf('.') );
- else
- title = p.getTitle();
- filePhotos.put(title, p);
- }
+ /**
+ * The assumption here is that for a given set only unique file-names will be loaded and the title field can be used. Later change to use the tags field (
+ * OrigFileName) and strip off the suffix.
+ *
+ * @param filename
+ * @return
+ */
+ private boolean checkIfLoaded(String filename) {
+
+ String title;
+ if (basefilename.lastIndexOf('.') > 0)
+ title = basefilename.substring(0, basefilename.lastIndexOf('.'));
+ else
+ return false;
+
+ if (filePhotos.containsKey(title))
+ return true;
+
+ return false;
}
-}
+ private String getUploadedTime(String filename) {
+
+ String title = "";
+ if (basefilename.lastIndexOf('.') > 0)
+ title = basefilename.substring(0, basefilename.lastIndexOf('.'));
+
+ if (filePhotos.containsKey(title)) {
+ Photo p = filePhotos.get(title);
+ if (p.getDatePosted() != null) {
+ return (smp.format(p.getDatePosted()));
+ }
+ }
+
+ return "";
+ }
+
+ private void getSetPhotos(String setName) throws FlickrException {
+ // Check if this is an existing set. If it is get all the photo list to avoid reloading already
+ // loaded photos.
+ ArrayList setIdarr;
+ setIdarr = setNameToId.get(setName);
+ if (setIdarr != null) {
+ setid = setIdarr.get(0);
+ PhotosetsInterface pi = flickr.getPhotosetsInterface();
+
+ Set extras = new HashSet();
+ /**
+ * A comma-delimited list of extra information to fetch for each returned record. Currently supported fields are: license, date_upload, date_taken,
+ * owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m,
+ * url_o
+ */
+
+ extras.add("date_upload");
+ extras.add("original_format");
+ extras.add("media");
+ // extras.add("url_o");
+ extras.add("tags");
+
+ int setPage = 1;
+ while (true) {
+ PhotoList tmpSet = pi.getPhotos(setid, extras, Flickr.PRIVACY_LEVEL_NO_FILTER, 500, setPage);
+
+ int tmpSetSize = tmpSet.size();
+ photos.addAll(tmpSet);
+ if (tmpSetSize < 500) {
+ break;
+ }
+ setPage++;
+ }
+ for (int i = 0; i < photos.size(); i++) {
+ filePhotos.put(photos.get(i).getTitle(), photos.get(i));
+ }
+ if (flickrDebug) {
+ logger.debug("Set title: " + setName + " id: " + setid + " found");
+ logger.debug(" Photos in Set already loaded: " + photos.size());
+ }
+ }
+ }
+
+ public void addPhotoToSet(String photoid, String setName) throws Exception {
+
+ ArrayList setIdarr;
+
+ // all_set_maps.
+
+ PhotosetsInterface psetsInterface = flickr.getPhotosetsInterface();
+
+ Photoset set = null;
+
+ if (setid == null) {
+ // In case it is a new photo-set.
+ setIdarr = setNameToId.get(setName);
+ if (setIdarr == null) {
+ // setIdarr should be null since we checked it getSetPhotos.
+ // Create the new set.
+ // set the setid .
+
+ String description = "";
+ set = psetsInterface.create(setName, description, photoid);
+ setid = set.getId();
+
+ setIdarr = new ArrayList();
+ setIdarr.add(new String(setid));
+ setNameToId.put(setName, setIdarr);
+
+ allSetsMap.put(set.getId(), set);
+ }
+ } else {
+ set = allSetsMap.get(setid);
+ psetsInterface.addPhoto(setid, photoid);
+ }
+ // Add to photos .
+
+ // Add Photo to existing set.
+ PhotosInterface photoInt = flickr.getPhotosInterface();
+ Photo p = photoInt.getPhoto(photoid);
+ if (p != null) {
+ photos.add(p);
+ String title;
+ if (basefilename.lastIndexOf('.') > 0)
+ title = basefilename.substring(0, basefilename.lastIndexOf('.'));
+ else
+ title = p.getTitle();
+ filePhotos.put(title, p);
+ }
+ }
+}
diff --git a/Flickr4Java/src/main/java/com/flickr4java/flickr/REST.java b/Flickr4Java/src/main/java/com/flickr4java/flickr/REST.java
index 256fdf23..4483f6df 100644
--- a/Flickr4Java/src/main/java/com/flickr4java/flickr/REST.java
+++ b/Flickr4Java/src/main/java/com/flickr4java/flickr/REST.java
@@ -177,7 +177,7 @@ public com.flickr4java.flickr.Response get(String path, Map para
com.flickr4java.flickr.Response response = null;
synchronized (mutex) {
- String strXml = scribeResponse.getBody();
+ String strXml = scribeResponse.getBody().trim();
if (Flickr.debugStream) {
logger.debug(strXml);
}
@@ -300,7 +300,7 @@ public com.flickr4java.flickr.Response post(String path, Map par
try {
com.flickr4java.flickr.Response response = null;
synchronized (mutex) {
- String strXml = scribeResponse.getBody();
+ String strXml = scribeResponse.getBody().trim();
if (Flickr.debugStream) {
logger.debug(strXml);
}
diff --git a/Flickr4Java/src/main/java/com/flickr4java/flickr/people/FaceTag.java b/Flickr4Java/src/main/java/com/flickr4java/flickr/people/FaceTag.java
new file mode 100644
index 00000000..3fdbee3d
--- /dev/null
+++ b/Flickr4Java/src/main/java/com/flickr4java/flickr/people/FaceTag.java
@@ -0,0 +1,145 @@
+package com.flickr4java.flickr.people;
+
+public class FaceTag {
+
+ private String id;
+
+ private String username;
+
+ private String realName;
+
+ private int iconFarm;
+
+ private int iconServer;
+
+ private String pathAlias;
+
+ private String addedById;
+
+ private int x;
+
+ private int y;
+
+ private int w;
+
+ private int h;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getRealName() {
+ return realName;
+ }
+
+ public void setRealName(String realName) {
+ this.realName = realName;
+ }
+
+ public int getIconFarm() {
+ return iconFarm;
+ }
+
+ public void setIconFarm(int iconFarm) {
+ this.iconFarm = iconFarm;
+ }
+
+ public int getIconServer() {
+ return iconServer;
+ }
+
+ public void setIconServer(int iconServer) {
+ this.iconServer = iconServer;
+ }
+
+ /**
+ * @return the user_id of the user who added the person
+ */
+ public String getAddedById() {
+ return addedById;
+ }
+
+ /**
+ * @param addedById the user_id who added the person
+ */
+ public void setAddedById(String addedById) {
+ this.addedById = addedById;
+ }
+
+ /**
+ * @return the x coordinate of the bounding box around the person
+ */
+ public int getX() {
+ return x;
+ }
+
+ /**
+ * @param x the x to set the coordinate of the bounding box around the person
+ */
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ /**
+ * @return the y coordinate of the bounding box around the person
+ */
+ public int getY() {
+ return y;
+ }
+
+ /**
+ * @param y the y to set the coordinate of the bounding box around the person
+ */
+ public void setY(int y) {
+ this.y = y;
+ }
+
+ /**
+ * @return the w coordinate of the bounding box around the person
+ */
+ public int getW() {
+ return w;
+ }
+
+ /**
+ * @param w the w to set the coordinate of the bounding box around the person
+ */
+ public void setW(int w) {
+ this.w = w;
+ }
+
+ /**
+ * @return the h coordinate of the bounding box around the person
+ */
+ public int getH() {
+ return h;
+ }
+
+ /**
+ * @param h the h to set the coordinate of the bounding box around the person
+ */
+ public void setH(int h) {
+ this.h = h;
+ }
+
+ public String getPathAlias() {
+ return pathAlias;
+ }
+
+ public void setPathAlias(String pathAlias) {
+ this.pathAlias = pathAlias;
+ }
+
+}
diff --git a/Flickr4Java/src/main/java/com/flickr4java/flickr/people/FacesTag.java b/Flickr4Java/src/main/java/com/flickr4java/flickr/people/FacesTag.java
new file mode 100644
index 00000000..3fdbee3d
--- /dev/null
+++ b/Flickr4Java/src/main/java/com/flickr4java/flickr/people/FacesTag.java
@@ -0,0 +1,145 @@
+package com.flickr4java.flickr.people;
+
+public class FaceTag {
+
+ private String id;
+
+ private String username;
+
+ private String realName;
+
+ private int iconFarm;
+
+ private int iconServer;
+
+ private String pathAlias;
+
+ private String addedById;
+
+ private int x;
+
+ private int y;
+
+ private int w;
+
+ private int h;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getRealName() {
+ return realName;
+ }
+
+ public void setRealName(String realName) {
+ this.realName = realName;
+ }
+
+ public int getIconFarm() {
+ return iconFarm;
+ }
+
+ public void setIconFarm(int iconFarm) {
+ this.iconFarm = iconFarm;
+ }
+
+ public int getIconServer() {
+ return iconServer;
+ }
+
+ public void setIconServer(int iconServer) {
+ this.iconServer = iconServer;
+ }
+
+ /**
+ * @return the user_id of the user who added the person
+ */
+ public String getAddedById() {
+ return addedById;
+ }
+
+ /**
+ * @param addedById the user_id who added the person
+ */
+ public void setAddedById(String addedById) {
+ this.addedById = addedById;
+ }
+
+ /**
+ * @return the x coordinate of the bounding box around the person
+ */
+ public int getX() {
+ return x;
+ }
+
+ /**
+ * @param x the x to set the coordinate of the bounding box around the person
+ */
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ /**
+ * @return the y coordinate of the bounding box around the person
+ */
+ public int getY() {
+ return y;
+ }
+
+ /**
+ * @param y the y to set the coordinate of the bounding box around the person
+ */
+ public void setY(int y) {
+ this.y = y;
+ }
+
+ /**
+ * @return the w coordinate of the bounding box around the person
+ */
+ public int getW() {
+ return w;
+ }
+
+ /**
+ * @param w the w to set the coordinate of the bounding box around the person
+ */
+ public void setW(int w) {
+ this.w = w;
+ }
+
+ /**
+ * @return the h coordinate of the bounding box around the person
+ */
+ public int getH() {
+ return h;
+ }
+
+ /**
+ * @param h the h to set the coordinate of the bounding box around the person
+ */
+ public void setH(int h) {
+ this.h = h;
+ }
+
+ public String getPathAlias() {
+ return pathAlias;
+ }
+
+ public void setPathAlias(String pathAlias) {
+ this.pathAlias = pathAlias;
+ }
+
+}
diff --git a/Flickr4Java/src/main/java/com/flickr4java/flickr/photos/PhotoUtils.java b/Flickr4Java/src/main/java/com/flickr4java/flickr/photos/PhotoUtils.java
index 9442fed4..698338b8 100644
--- a/Flickr4Java/src/main/java/com/flickr4java/flickr/photos/PhotoUtils.java
+++ b/Flickr4Java/src/main/java/com/flickr4java/flickr/photos/PhotoUtils.java
@@ -79,6 +79,7 @@ public static final Photo createPhoto(Element photoElement, Element defaultEleme
photo.setMedia(photoElement.getAttribute("media"));
photo.setMediaStatus(photoElement.getAttribute("media_status"));
photo.setPathAlias(photoElement.getAttribute("pathalias"));
+ photo.setViews(photoElement.getAttribute("views"));
Element peopleElement = (Element) photoElement.getElementsByTagName("people").item(0);
if(peopleElement != null){
diff --git a/Flickr4Java/src/main/java/com/flickr4java/flickr/photosets/PhotosetsInterface.java b/Flickr4Java/src/main/java/com/flickr4java/flickr/photosets/PhotosetsInterface.java
index 0546ce65..5dc6e853 100644
--- a/Flickr4Java/src/main/java/com/flickr4java/flickr/photosets/PhotosetsInterface.java
+++ b/Flickr4Java/src/main/java/com/flickr4java/flickr/photosets/PhotosetsInterface.java
@@ -313,7 +313,23 @@ public Photoset getInfo(String photosetId) throws FlickrException {
* @throws FlickrException
*/
public Photosets getList(String userId) throws FlickrException {
- return getList(userId, 0, 0);
+ return getList(userId, 0, 0, null);
+ }
+
+ /**
+ * Get a list of all photosets for the specified user.
+ *
+ * This method does not require authentication. But to get a Photoset into the list, that contains just private photos, the call needs to be authenticated.
+ *
+ * @param userId
+ * The User id
+ * @param primaryPhotoExtras
+ * A comma-delimited list of extra information to fetch for the primary photo
+ * @return The Photosets collection
+ * @throws FlickrException
+ */
+ public Photosets getList(String userId, String primaryPhotoExtras) throws FlickrException {
+ return getList(userId, 0, 0, primaryPhotoExtras);
}
/**
@@ -327,10 +343,12 @@ public Photosets getList(String userId) throws FlickrException {
* The number of photosets per page
* @param page
* The page offset
+ * @param primaryPhotoExtras
+ * A comma-delimited list of extra information to fetch for the primary photo
* @return The Photosets collection
* @throws FlickrException
*/
- public Photosets getList(String userId, int perPage, int page) throws FlickrException {
+ public Photosets getList(String userId, int perPage, int page, String primaryPhotoExtras) throws FlickrException {
Map parameters = new HashMap();
parameters.put("method", METHOD_GET_LIST);
@@ -346,6 +364,10 @@ public Photosets getList(String userId, int perPage, int page) throws FlickrExce
parameters.put("page", String.valueOf(page));
}
+ if (primaryPhotoExtras != null) {
+ parameters.put("primary_photo_extras", primaryPhotoExtras);
+ }
+
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
@@ -368,7 +390,13 @@ public Photosets getList(String userId, int perPage, int page) throws FlickrExce
owner.setId(photosetElement.getAttribute("owner"));
photoset.setOwner(owner);
- Photo primaryPhoto = new Photo();
+ Element primaryPhotoExtrasEl = XMLUtilities.getChild(photosetElement, "primary_photo_extras");
+ Photo primaryPhoto;
+ if (primaryPhotoExtrasEl != null) {
+ primaryPhoto = PhotoUtils.createPhoto(primaryPhotoExtrasEl);
+ } else {
+ primaryPhoto = new Photo();
+ }
primaryPhoto.setId(photosetElement.getAttribute("primary"));
primaryPhoto.setSecret(photosetElement.getAttribute("secret")); // TODO verify that this is the secret for the photo
primaryPhoto.setServer(photosetElement.getAttribute("server")); // TODO verify that this is the server for the photo
diff --git a/Flickr4Java/src/main/java/com/flickr4java/flickr/test/TestInterface.java b/Flickr4Java/src/main/java/com/flickr4java/flickr/test/TestInterface.java
index ddde5d40..7dc67ae6 100644
--- a/Flickr4Java/src/main/java/com/flickr4java/flickr/test/TestInterface.java
+++ b/Flickr4Java/src/main/java/com/flickr4java/flickr/test/TestInterface.java
@@ -3,6 +3,7 @@
*/
package com.flickr4java.flickr.test;
+import com.flickr4java.flickr.Flickr;
import com.flickr4java.flickr.FlickrException;
import com.flickr4java.flickr.Response;
import com.flickr4java.flickr.Transport;
@@ -10,7 +11,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Text;
-import org.xml.sax.SAXException;
import java.util.Collection;
import java.util.HashMap;
@@ -52,6 +52,7 @@ public TestInterface(String apiKey, String sharedSecret, Transport transportAPI)
public Collection echo(Map params) throws FlickrException {
Map parameters = new HashMap();
parameters.put("method", METHOD_ECHO);
+ parameters.put(Flickr.API_KEY, apiKey);
parameters.putAll(params);
Response response = transport.post(transport.getPath(), parameters, apiKey, sharedSecret);
@@ -65,7 +66,6 @@ public Collection echo(Map params) throws FlickrExcepti
* A testing method which checks if the caller is logged in then returns a User object.
*
* @return The User object
- * @throws SAXException
* @throws FlickrException
*/
public User login() throws FlickrException {
diff --git a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/BulkUploaderTest.java b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/BulkUploaderTest.java
new file mode 100644
index 00000000..3739b10a
--- /dev/null
+++ b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/BulkUploaderTest.java
@@ -0,0 +1,211 @@
+/* Copyright 2004, Aetrion LLC. All Rights Reserved. */
+
+package com.flickr4java.flickr.test;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.junit.Test;
+
+import com.flickr4java.flickr.FlickrException;
+import com.flickr4java.flickr.photos.PhotosInterface;
+import com.flickr4java.flickr.uploader.UploadMetaData;
+import com.flickr4java.flickr.uploader.Uploader;
+import com.flickr4java.flickr.util.IOUtilities;
+
+/**
+ * @author Anthony Eden
+ */
+public class UploaderTest extends Flickr4JavaTest {
+
+ /**
+ * Test photo uploading using a byte array.
+ *
+ * @throws IOException
+ * @throws FlickrException
+ */
+ @Test
+ public void testUploadByteArray() throws IOException, FlickrException {
+ File imageFile = new File(testProperties.getImageFile());
+ InputStream in = null;
+ Uploader uploader = flickr.getUploader();
+ PhotosInterface pint = flickr.getPhotosInterface();
+
+ ByteArrayOutputStream out = null;
+ try {
+ in = new FileInputStream(imageFile);
+ out = new ByteArrayOutputStream();
+ int b = -1;
+ while ((b = in.read()) != -1) {
+ out.write((byte) b);
+ }
+ UploadMetaData metaData = buildPrivatePhotoMetadata();
+ // check correct handling of escaped value
+ metaData.setTitle("óöä");
+ String photoId = uploader.upload(out.toByteArray(), metaData);
+ assertNotNull(photoId);
+ pint.delete(photoId);
+ } finally {
+ IOUtilities.close(in);
+ IOUtilities.close(out);
+ }
+ }
+
+ /**
+ * Test photo upload using an InputStream.
+ *
+ * @throws IOException
+ * @throws FlickrException
+ */
+ @Test
+ public void testUploadInputStream() throws IOException, FlickrException {
+ File imageFile = new File(testProperties.getImageFile());
+ InputStream in = null;
+ Uploader uploader = flickr.getUploader();
+ PhotosInterface pint = flickr.getPhotosInterface();
+
+ try {
+ in = new FileInputStream(imageFile);
+ UploadMetaData metaData = buildPrivatePhotoMetadata();
+ metaData.setPublicFlag(false);
+ // check correct handling of escaped value
+ metaData.setTitle("óöä");
+ String photoId = uploader.upload(in, metaData);
+ assertNotNull(photoId);
+ pint.delete(photoId);
+ } finally {
+ IOUtilities.close(in);
+ }
+ }
+
+ /**
+ * Test photo replace using an InputStream.
+ *
+ * @throws IOException
+ * @throws FlickrException
+ */
+ @Test
+ public void testReplaceInputStream() throws IOException, FlickrException {
+ Uploader uploader = flickr.getUploader();
+ PhotosInterface pint = flickr.getPhotosInterface();
+ File imageFile = new File(testProperties.getImageFile());
+ InputStream uploadIS = null;
+ String photoId = null;
+ try {
+ uploadIS = new FileInputStream(imageFile);
+
+ // Upload a photo, which we'll replace, then delete
+ UploadMetaData metaData = buildPrivatePhotoMetadata();
+ photoId = uploader.upload(uploadIS, metaData);
+ } finally {
+ IOUtilities.close(uploadIS);
+ }
+
+ InputStream replaceIS = null;
+ try {
+ replaceIS = new FileInputStream(imageFile);
+
+ try {
+ photoId = uploader.replace(replaceIS, photoId, false);
+ assertNotNull(photoId);
+ } catch (FlickrException e) {
+ // Error code 1 means test account is not pro so don't fail test because of that
+ if (!e.getErrorCode().equals("1")) {
+ throw e;
+ }
+ }
+ pint.delete(photoId);
+ } finally {
+ IOUtilities.close(replaceIS);
+ }
+ }
+
+ /**
+ * Test photo replace using a byte array.
+ *
+ * @throws IOException
+ * @throws FlickrException
+ */
+ @Test
+ public void testReplaceByteArray() throws IOException, FlickrException {
+ File imageFile = new File(testProperties.getImageFile());
+ InputStream in = null;
+ ByteArrayOutputStream out = null;
+ Uploader uploader = flickr.getUploader();
+ PhotosInterface pint = flickr.getPhotosInterface();
+
+ try {
+ in = new FileInputStream(imageFile);
+ out = new ByteArrayOutputStream();
+ int b = -1;
+ while ((b = in.read()) != -1) {
+ out.write((byte) b);
+ }
+
+ // Upload a photo, which we'll replace, then delete
+ UploadMetaData metaData = buildPrivatePhotoMetadata();
+ String photoId = uploader.upload(out.toByteArray(), metaData);
+
+ try {
+ photoId = uploader.replace(out.toByteArray(), photoId, false);
+ assertNotNull(photoId);
+ } catch (FlickrException e) {
+ // Error code 1 means test account is not pro so don't fail test because of that
+ if (!e.getErrorCode().equals("1")) {
+ throw e;
+ }
+ }
+
+ pint.delete(photoId);
+ } finally {
+ IOUtilities.close(in);
+ }
+ }
+
+ /**
+ * Build {@link UploadMetaData} with public set to false so uploaded photos are private.
+ *
+ * @return
+ */
+ private UploadMetaData buildPrivatePhotoMetadata() {
+ UploadMetaData uploadMetaData = new UploadMetaData();
+ uploadMetaData.setPublicFlag(false);
+ return uploadMetaData;
+ }
+
+
+ @Test
+ public void testUploadByteArray() throws IOException, FlickrException {
+ File imageFile = new File(testProperties.getImageFile());
+ InputStream in = null;
+ Uploader uploader = flickr.getUploader();
+ PhotosInterface pint = flickr.getPhotosInterface();
+
+ ByteArrayOutputStream out = null;
+ try {
+ in = new FileInputStream(imageFile);
+ out = new ByteArrayOutputStream();
+ int b = -1;
+ while ((b = in.read()) != -1) {
+ out.write((byte) b);
+ }
+ UploadMetaData metaData = buildPrivatePhotoMetadata();
+ // check correct handling of escaped value
+ metaData.setTitle("óöä");
+ String photoId = uploader.upload(out.toByteArray(), metaData);
+ assertNotNull(photoId);
+ pint.delete(photoId);
+ } finally {
+ IOUtilities.close(in);
+ IOUtilities.close(out);
+ }
+ }
+
+
+
+}
diff --git a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/FaceRecInterfaceRecTest.java b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/FaceRecInterfaceRecTest.java
new file mode 100644
index 00000000..07635601
--- /dev/null
+++ b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/FaceRecInterfaceRecTest.java
@@ -0,0 +1,57 @@
+/**
+ * @author acaplan
+ */
+package com.flickr4java.flickr.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import com.flickr4java.flickr.FlickrException;
+import com.flickr4java.flickr.galleries.GalleriesInterface;
+import com.flickr4java.flickr.galleries.Gallery;
+
+import org.junit.After;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * @author acaplan
+ *
+ */
+public class GalleriesInterfaceTest extends Flickr4JavaTest {
+
+ @After
+ public void tearDown() {
+ flickr = null;
+ }
+
+ @Test
+ public void testGetList() throws FlickrException {
+ GalleriesInterface iface = flickr.getGalleriesInterface();
+ List galleries = iface.getList(testProperties.getNsid(), 10, 1);
+ assertNotNull(galleries);
+ assertFalse(galleries.isEmpty());
+ }
+
+ @Ignore
+ @Test
+ public void testCreate() throws FlickrException {
+ GalleriesInterface iface = flickr.getGalleriesInterface();
+ Gallery gallery = iface.create("test_gallery", "test gallery", "2732893596");
+ assertNotNull(gallery);
+ assertNotNull(gallery.getId());
+ assertEquals("test_gallery", gallery.getTitle());
+ assertEquals("test gallery", gallery.getDesc());
+ }
+
+ @Test
+ public void testGetInfo() throws FlickrException {
+ GalleriesInterface iface = flickr.getGalleriesInterface();
+ Gallery gallery = iface.getInfo("1979953-72157629277637049");
+ assertNotNull(gallery);
+ assertEquals("Motorcycle Pics", gallery.getTitle());
+ }
+}
diff --git a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/GroupsInterfaceTest.java b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/GroupsInterfaceTest.java
index 2ac30513..19d00fdc 100644
--- a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/GroupsInterfaceTest.java
+++ b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/GroupsInterfaceTest.java
@@ -22,8 +22,6 @@
*/
public class GroupsInterfaceTest extends Flickr4JavaTest {
- public static final String TEST_JOIN_GROUP = "2173840@N20";
-
public void deprecatedBrowse() throws FlickrException {
GroupsInterface iface = flickr.getGroupsInterface();
Category cat = iface.browse(null);
@@ -102,19 +100,33 @@ public void testSearchPage() throws FlickrException {
@Test
public void testJoinLeave() throws FlickrException {
-
GroupsInterface iface = flickr.getGroupsInterface();
- Group group = iface.getInfo(TEST_JOIN_GROUP);
+ Group group = iface.getInfo(testProperties.getGroupId());
int cntBeforeJoin = group.getMembers();
- iface.join(TEST_JOIN_GROUP, null);
- group = iface.getInfo(TEST_JOIN_GROUP);
- int cntAfterJoin = group.getMembers();
- assertTrue("Member count increased by 1", cntBeforeJoin + 1 == cntAfterJoin);
-
- iface.leave(TEST_JOIN_GROUP, false);
- group = iface.getInfo(TEST_JOIN_GROUP);
- int cntAfterLeave = group.getMembers();
- assertTrue("Member count decreased by 1", cntAfterLeave == cntBeforeJoin);
+ try {
+ iface.join(testProperties.getGroupId(), null);
+ group = iface.getInfo(testProperties.getGroupId());
+ int cntAfterJoin = group.getMembers();
+ assertTrue("Member count increased by 1", cntBeforeJoin + 1 == cntAfterJoin);
+ } catch (FlickrException e) {
+ // Ignore if user is already in group
+ if (!e.getErrorCode().equals("4")) {
+ throw e;
+ }
+ }
+
+ try {
+ iface.leave(testProperties.getGroupId(), false);
+ group = iface.getInfo(testProperties.getGroupId());
+ int cntAfterLeave = group.getMembers();
+ assertTrue("Member count decreased by 1", cntAfterLeave == cntBeforeJoin);
+ } catch (FlickrException e) {
+ // Ignore if user doesn't have delete permissions
+ if (!e.getErrorCode().equals("99")) {
+ throw e;
+ }
+ }
+
}
}
diff --git a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java
index a55d6ebf..ad644391 100644
--- a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java
+++ b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java
@@ -96,7 +96,7 @@ public void testGetRecentValues() throws FlickrException {
String namespace = "ceramics";
String predicate = "material";
Calendar addedSince = Calendar.getInstance();
- addedSince.add(Calendar.YEAR, -5);
+ addedSince.add(Calendar.YEAR, -10);
NamespacesList list = machinetagsInterface.getRecentValues(namespace, predicate, addedSince.getTime());
assertTrue(list.size() >= 3);
boolean contentFound = false;
diff --git a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/PandaInterfaceMarkTest.java b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/PandaInterfaceMarkTest.java
new file mode 100644
index 00000000..537c57df
--- /dev/null
+++ b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/PandaInterfaceMarkTest.java
@@ -0,0 +1,45 @@
+/* Copyright 2004, Aetrion LLC. All Rights Reserved. */
+
+package com.flickr4java.flickr.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import com.flickr4java.flickr.FlickrException;
+import com.flickr4java.flickr.panda.Panda;
+import com.flickr4java.flickr.panda.PandaInterface;
+import com.flickr4java.flickr.photos.Photo;
+import com.flickr4java.flickr.photos.PhotoList;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+/**
+ * @author mago
+ * @version $Id: PandaInterfaceTest.java,v 1.1 2009/06/18 21:56:43 x-mago Exp $
+ */
+public class PandaInterfaceTest extends Flickr4JavaTest {
+
+ @Test
+ public void testGetList() throws FlickrException {
+ PandaInterface iface = flickr.getPandaInterface();
+ ArrayList list = iface.getList();
+ assertNotNull(list);
+ Panda p = list.get(0);
+ assertEquals("ling ling", p.getName());
+ p = list.get(1);
+ assertEquals("hsing hsing", p.getName());
+ p = list.get(2);
+ assertEquals("wang wang", p.getName());
+ }
+
+ @Test
+ public void testGetPhotos() throws FlickrException {
+ PandaInterface iface = flickr.getPandaInterface();
+ Panda p = new Panda();
+ p.setName("ling ling");
+ PhotoList list = iface.getPhotos(p, null, 1, 50);
+ assertNotNull(list);
+ }
+}
diff --git a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/PhotosetsInterfaceTest.java b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/PhotosetsInterfaceTest.java
index d39bc869..13d75cdc 100644
--- a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/PhotosetsInterfaceTest.java
+++ b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/PhotosetsInterfaceTest.java
@@ -20,6 +20,7 @@
import org.junit.Before;
import org.junit.Test;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -118,10 +119,17 @@ public void testGetList() throws FlickrException {
}
@Test
- public void testGetList2() throws FlickrException {
+ public void testGetListWithExtras() throws FlickrException {
PhotosetsInterface iface = flickr.getPhotosetsInterface();
- Photosets photosets = iface.getList("26095690@N00");
+ Photosets photosets = iface.getList(testProperties.getNsid(), "last_update, owner_name");
assertNotNull(photosets);
+ Collection photosetsList = photosets.getPhotosets();
+ assertFalse(photosetsList.isEmpty());
+ Photoset photoset = photosetsList.iterator().next();
+ assertNotNull(photoset.getPrimaryPhoto().getLastUpdate());
+ assertNotNull(photoset.getPrimaryPhoto().getOwner());
+ assertNotNull(photoset.getPrimaryPhoto().getOwner().getUsername());
+ assertTrue(photoset.getPrimaryPhoto().getOwner().getUsername().length() > 0);
}
@Test
diff --git a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/ReflectionInterfaceTest.java b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/ReflectionInterfaceTest.java
index 8beb0393..81496bd4 100644
--- a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/ReflectionInterfaceTest.java
+++ b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/ReflectionInterfaceTest.java
@@ -38,7 +38,7 @@ public void testGetMethodInfo_public() throws FlickrException {
assertFalse(method.needsLogin());
assertNotNull(method.getArguments());
- assertEquals(7, method.getArguments().size());
+ assertEquals(5, method.getArguments().size());
Collection args = method.getArguments();
Iterator argsIterator = args.iterator();
@@ -51,14 +51,6 @@ public void testGetMethodInfo_public() throws FlickrException {
assertEquals("date", date.getName());
assertTrue(date.isOptional());
- Argument panda = argsIterator.next();
- assertEquals("use_panda", panda.getName());
- assertTrue(panda.isOptional());
-
- Argument offsetDays = argsIterator.next();
- assertEquals("offset_days", offsetDays.getName());
- assertTrue(offsetDays.isOptional());
-
Argument extras = argsIterator.next();
assertEquals("extras", extras.getName());
assertTrue(extras.isOptional());
diff --git a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/UploaderTest.java b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/UploaderTest.java
index b970c5b1..e268e992 100644
--- a/Flickr4Java/src/test/java/com/flickr4java/flickr/test/UploaderTest.java
+++ b/Flickr4Java/src/test/java/com/flickr4java/flickr/test/UploaderTest.java
@@ -4,20 +4,20 @@
import static org.junit.Assert.assertNotNull;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.junit.Test;
-
import com.flickr4java.flickr.FlickrException;
import com.flickr4java.flickr.photos.PhotosInterface;
import com.flickr4java.flickr.uploader.UploadMetaData;
import com.flickr4java.flickr.uploader.Uploader;
import com.flickr4java.flickr.util.IOUtilities;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
/**
* @author Anthony Eden
*/
@@ -49,7 +49,15 @@ public void testUploadByteArray() throws IOException, FlickrException {
metaData.setTitle("óöä");
String photoId = uploader.upload(out.toByteArray(), metaData);
assertNotNull(photoId);
- pint.delete(photoId);
+ try {
+ pint.delete(photoId);
+ } catch (FlickrException e) {
+ // Ignore if user doesn't have delete permissions
+ // This will leave a *private* photo in the test account's photostream!
+ if (!e.getErrorCode().equals("99")) {
+ throw e;
+ }
+ }
} finally {
IOUtilities.close(in);
IOUtilities.close(out);
@@ -77,7 +85,16 @@ public void testUploadInputStream() throws IOException, FlickrException {
metaData.setTitle("óöä");
String photoId = uploader.upload(in, metaData);
assertNotNull(photoId);
- pint.delete(photoId);
+ try {
+ pint.delete(photoId);
+ } catch (FlickrException e) {
+ // Ignore if user doesn't have delete permissions
+ // This will leave a *private* photo in the test account's photostream!
+ if (!e.getErrorCode().equals("99")) {
+ throw e;
+ }
+ }
+
} finally {
IOUtilities.close(in);
}
@@ -119,7 +136,16 @@ public void testReplaceInputStream() throws IOException, FlickrException {
throw e;
}
}
- pint.delete(photoId);
+ try {
+ pint.delete(photoId);
+ } catch (FlickrException e) {
+ // Ignore if user doesn't have delete permissions
+ // This will leave a *private* photo in the test account's photostream!
+ if (!e.getErrorCode().equals("99")) {
+ throw e;
+ }
+ }
+
} finally {
IOUtilities.close(replaceIS);
}
@@ -161,7 +187,16 @@ public void testReplaceByteArray() throws IOException, FlickrException {
}
}
- pint.delete(photoId);
+ try {
+ pint.delete(photoId);
+ } catch (FlickrException e) {
+ // Ignore if user doesn't have delete permissions
+ // This will leave a *private* photo in the test account's photostream!
+ if (!e.getErrorCode().equals("99")) {
+ throw e;
+ }
+ }
+
} finally {
IOUtilities.close(in);
}
diff --git a/README.md b/README.md
index 1f0c8fb7..74e930b1 100644
--- a/README.md
+++ b/README.md
@@ -14,20 +14,24 @@ To use the API just construct an instance of the class `com.flickr4java.flickr.t
For example, to send a test ping to the Flickr service:
String apiKey = "YOUR_API_KEY";
- Flickr f = new Flickr(apiKey);
+ String sharedSecret = "YOUR_SHARED_SECRET";
+ Flickr f = new Flickr(apiKey, sharedSecret, new REST());
TestInterface testInterface = f.getTestInterface();
- Collection results = testInterface.echo(Collections.EMPTY_LIST);
+ Collection results = testInterface.echo(Collections.EMPTY_MAP);
__Please note:__ this library is not thread safe.
### Requirements
-This API has been tested with JDK 1.4 and JDK 1.5. The default distribution is built with JDK 1.5 (it builds and runs fine under 1.6 and 1.7 too though).
+This API has been tested with JDK 1.5 and JDK 1.6. The default distribution is built with JDK 1.5 (it builds and runs fine under 1.6 and 1.7 too though).
An API key is required to use this API. You can [request one on Flickr](http://www.flickr.com/services/api/).
-[scribe-java (v.1.3.2)](https://github.com/fernandezpablo85/scribe-java/wiki/Getting-Started) is also required for the OAuth functionality.
+#### Required libraries
+
+- [scribe-java (v.1.3.2 onwards)](https://github.com/fernandezpablo85/scribe-java/wiki/Getting-Started) (required for the OAuth functionality).
+- [log4j](http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip) (runtime dependency for logging)
### Download
@@ -39,7 +43,7 @@ An API key is required to use this API. You can [request one on Flickr](http://
com.flickr4java
flickr4java
- 2.11
+ 2.12
Flickr4Java is now available on Maven Central so the above settings should be all you need (it used to only be available on [JCenter](https://bintray.com/bintray/jcenter).