Utilisation de l'API Flickr
Bonjour,
Y a-t-il quelqu'un qui a utilisé auparavant l'API Flickr?
http://www.flickr.com/services/api/
Problème avec l'API Flickr
Bonjour,
J'ai testé l'exemple AuthExample.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import com.aetrion.flickr.Flickr;
import com.aetrion.flickr.FlickrException;
import com.aetrion.flickr.REST;
import com.aetrion.flickr.RequestContext;
import com.aetrion.flickr.auth.Auth;
import com.aetrion.flickr.auth.AuthInterface;
import com.aetrion.flickr.auth.Permission;
import com.aetrion.flickr.util.IOUtilities;
/**
* Demonstrates the authentication-process.<p>
*
* If you registered API keys, you find them with the shared secret at your
* <a href="http://www.flickr.com/services/api/registered_keys.gne">list of API keys</a>
*
* @author mago
* @version $Id: AuthExample.java,v 1.6 2009/08/25 19:37:45 x-mago Exp $
*/
public class AuthExample {
Flickr f;
RequestContext requestContext;
String frob = "";
String token = "";
Properties properties = null;
public AuthExample() throws ParserConfigurationException, IOException, SAXException {
InputStream in = null;
try {
in = getClass().getResourceAsStream("/setup.properties");
properties = new Properties();
properties.load(in);
} finally {
IOUtilities.close(in);
}
f = new Flickr(
properties.getProperty("apiKey"),
properties.getProperty("secret"),
new REST("www.flickr.com")
);
Flickr.debugStream = false;
requestContext = RequestContext.getRequestContext();
AuthInterface authInterface = f.getAuthInterface();
try {
frob = authInterface.getFrob();
} catch (FlickrException e) {
e.printStackTrace();
}
System.out.println("frob: " + frob);
URL url = authInterface.buildAuthenticationUrl(Permission.DELETE, frob);
System.out.println("Press return after you granted access at this URL:");
System.out.println(url.toExternalForm());
BufferedReader infile =
new BufferedReader ( new InputStreamReader (System.in) );
String line = infile.readLine();
try {
Auth auth = authInterface.getToken(frob);
System.out.println("Authentication success");
// This token can be used until the user revokes it.
System.out.println("Token: " + auth.getToken());
System.out.println("nsid: " + auth.getUser().getId());
System.out.println("Realname: " + auth.getUser().getRealName());
System.out.println("Username: " + auth.getUser().getUsername());
System.out.println("Permission: " + auth.getPermission().getType());
} catch (FlickrException e) {
System.out.println("Authentication failed");
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
AuthExample t = new AuthExample();
} catch(Exception e) {
e.printStackTrace();
}
System.exit(0);
} |
mais un problème est survenu sur eclipse:
Citation:
java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at exemples.AuthExample.<init>(AuthExample.java:43)
at exemples.AuthExample.main(AuthExample.java:84)
Ce que j'ai compris est que le problème provient du fichier setup.properties mais je n'ai pas compris comment le corriger.
Pouvez-vous m'aider?