How do we display a photo from Picasa java API?

白昼怎懂夜的黑 提交于 2019-12-03 04:08:22
Daxon

Quite Simple

 PhotoEntry photo = //somehow I get the instance
    photo.getMediaThumbnails().get(0).getUrl()

You can use this way to get that 400/800px photo.

You only have to change the result URL that is given. Change the s144/s400/s800 value of the URL

BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s72/DSC09176.JPG
BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s144/DSC09176.JPG
BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s288/DSC09176.JPG
BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s400/DSC09176.JPG
BLAH com/_BwderBVv7wg/XXXXXXXXX/AAAAAAAAAME/HdXja0HclK0/s800/DSC09176.JPG

The following was answered by a community member of google picasa api:

Take a look at

http://code.google.com/apis/picasaweb/docs/2.0/reference.html#Parameters

It explains how you can control the size of the image that the media:content link points to as well as how you can request different thumbsizes for the media:thumbnail links. Also listed are the valid size values available. Note though, that you can only access images up to 800px in size (width or height, whatever is larger) from websites.

For instance:

GET /feed/api/user//albumid/? kind=photo&imgmax=800&thumbsize=512,400,160c

will give you a link to an 800px version in the media:content link, a link to the uncropped 512px and 400px version in the first two media:thumbnail elements and a square-cropped 160x160 thumbnail in the third thumbnail element.

Cheers, Detlev

Boris Nebosenko

If you are using Picasa Java API and need to get image URL after uploading try to use following code

    try {
        File photoFile = new File(getFileName());
        service = new PicasawebService(applicationName);
        MediaFileSource photoMedia = new MediaFileSource(photoFile, "image/jpg");
        URL albumPostUrl = new URL(String.format("http://picasaweb.google.com/data/feed/api/user/%1$s/albumid/%2$s", getUserName(), getAlbumId()));
        PhotoEntry returnedPhoto = service.insert(albumPostUrl, PhotoEntry.class, photoMedia);

        String href = returnedPhoto.getHtmlLink().getHref();

        if (returnedPhoto.getMediaContents().size() > 0) {
            // !!!!!!!!!!!!!!!This is exactly JPEG URL
            href = returnedPhoto.getMediaContents().get(0).getUrl();
        }
        logger.info(String.format("Image published: <%s>", href));
        return href;
    } catch (AuthenticationException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
    } catch (MalformedURLException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
    } catch (ServiceException e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!