Picasa Web Album JAVA API
6.Februar 2008
Benutzung im Java Desktop Client
Laden der Alben eines Benutzers
PicasawebService picasa = new PicasawebService("exampleCo-exampleApp-1");
String url = "http://picasaweb.google.com/data/feed/api/user/<username>?kind=album";
URL albumsUrl = new URL(url);
// Send the request for the user's albums.
AlbumFeed albums = picasa.getFeed(albumsUrl, AlbumFeed.class);
List<AlbumEntry> entries = albums.getEntries(AlbumEntry.class);
for (AlbumEntry album : entries) {
//do something with the albums
}
Albumdetails Abrufen und Bilder eines Albums anzeigen
//URL for the AlbumFeed String url = albumEntry.getFeedLink().getHref() + "?kind=photo"; //the albuFeed contains the album details AlbumFeed feed = getService().getFeed(new URL(url), AlbumFeed.class); //a photoEntry contains all photo infos including the urls to the thubnails and image data List<PhotoEntry> photos = feed.getPhotoEntries();
Benutzung eines HTTP-Proxys
In Java lässt sich die Benutzung eines HTTP-Proxys für http/https Zugriffe wie folgt vornehmen:
Properties systemSettings = System.getProperties();
systemSettings.put("https.proxySet", "true");
systemSettings.put("http.proxyHost", proxyHost);
systemSettings.put("http.proxyPort", proxyPort);
systemSettings.put("proxySet", "true");
systemSettings.put("https.proxyHost", proxyHost);
systemSettings.put("https.proxyPort", proxyPort);
System.setProperties(systemSettings);
Http- und https-Zugriffe sollten nun die Proxy-Einstellungen berücksichtigen.
HTTP-Proxy-Authentifikation
Ggf. erfordert der HTTP-Proxy eine Authentifikation. Dabei ist für normale JAVA-Web Zugriffe Folgendes notwendig:
URL url = new URL(theUrl);
URLConnection conn = url.openConnection();
String encoded = getBas64EncodeCredentials(getProxyUser(), getProxyPasswd());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
conn.connect();
Googles API kann ebenfalls mit einer Authentifizierung an einem HTTP-Proxy umgehen; dazu ist Folgendes setzen:
String base64encodedCredentials = "Basic " + getBas64EncodeCredentials(getProxyUser(), getProxyPasswd());
picasaService.getRequestFactory().setPrivateHeader("Proxy-Authorization", base64encodedCredentials);
Base64-codierte Credentials:
private String getBas64EncodeCredentials(String user, String passwd) {
String userPasswd = user + ":" + passwd;
String encoded = new String(Base64.encode(userPasswd.getBytes()));
return encoded;
}
Entry Filed under: Google DATA API, authentication. Schlagworte: http, java, Picasa, proxy.
1 Comment Add your own
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed
1.
mic | 6.Februar 2008 at 11:07
//read photos of album
String url = albumEntry.getFeedLink().getHref() + „?kind=photo“;
AlbumFeed feed = getService().getFeed(new URL(url), AlbumFeed.class);
List photos = feed.getPhotoEntries();