PicasawebService myService = new PicasawebService("example");
myService.setUserCredentials("<ここにユーザID>", "<ここにパスワード>");
URL albumPostUrl = new URL("http://picasaweb.google.com/data/feed/api/user/<ここにユーザID>/albumid/<ここにアルバムID>");
PhotoEntry myPhoto = new PhotoEntry();
myPhoto.setTitle(new PlainTextConstruct("ファイル名"));
myPhoto.setDescription(new PlainTextConstruct("タイトル"));
myPhoto.setClient("クライアント名");//ちょっとここは不明
MediaFileSource myMedia = new MediaFileSource(new File("C:\\temp\\kiku.jpg"), "image/jpeg");
myPhoto.setMediaSource(myMedia);
PhotoEntry returnedPhoto = myService.insert(albumPostUrl, myPhoto);
最後のreturnedPhoto には、アップしたファイルのURLなどが格納されています。2011-05-17
Picasaへ写真を投稿する
以前の、GooglePicasa APIを試してみたの続編で、JavaでPicasaに写真をアップロードするサンプルです。
2010-02-25
GooglePicasa APIを試してみた
PicasaのAPIを試してみました。基本的には、Developer's Guide: Java を参考にしてます。
SDKインストールについて
Java Google Data APIs Client Libraryをダウンロードしてパスを通せばいいのですが、不足のライブラリを言われます。
とりあえず試したのは、アルバムと写真のリストの入手です。以下のサンプルで出力している内容自体はあまり意味はありません。どんな情報が出てくるのかは、各自で試してみてください。
アルバムリストの入手
フォトリストの入手
SDKインストールについて
Java Google Data APIs Client Libraryをダウンロードしてパスを通せばいいのですが、不足のライブラリを言われます。
- Google-Collect
- JavaMail
とりあえず試したのは、アルバムと写真のリストの入手です。以下のサンプルで出力している内容自体はあまり意味はありません。どんな情報が出てくるのかは、各自で試してみてください。
アルバムリストの入手
public void getAlbumList() throws MalformedURLException, IOException, ServiceException {
PicasawebService myService = new PicasawebService("example");
myService.setUserCredentials("USERID", "PASSWD");
URL feedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/USERID?kind=album");
UserFeed myUserFeed = myService.getFeed(feedUrl, UserFeed.class);
for (AlbumEntry myAlbum : myUserFeed.getAlbumEntries()) {
System.out.println(myAlbum.getTitle().getPlainText());
System.out.println(myAlbum.getId());
}
}
フォトリストの入手
public void getPhotoList() throws MalformedURLException, IOException, ServiceException {
PicasawebService myService = new PicasawebService("example");
URL feedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/USERID/albumid/ALUBUMID");
myService.setUserCredentials("USERID", "PASSWD");
AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class);
for (PhotoEntry photo : feed.getPhotoEntries()) {
System.out.println(photo.getTitle().getPlainText());
System.out.println(photo.getHtmlLink().getHref());
System.out.println(photo.getId());
}
}
}
登録:
投稿 (Atom)