使用flickrj-android获取私人照片

时间:2013-08-15 16:13:20

标签: android private flickr photos flickrj

我正在使用开源库:https://code.google.com/p/flickrj-android/并且有一个示例如何从flickr获取照片。主要问题是我只获得公开照片。如何管理获取私人流/照片? 有没有人设法获得私人流?

2 个答案:

答案 0 :(得分:1)

使用Flickrj-android,您需要使用此方法:

 Flickr flickr = new Flickr(API_KEY,SHARED_SECRET,new REST());
    Set<String> extras = new HashSet();

    // A set of extra info we want Flickr to give back. Go to the API page to see the other size options available.
    extras.add("url_o");
    extras.add("original_format");

    //A request for a list of the photos in a set. The first zero is the privacy filter,
    // the second is the Pages, and the third is the Per-Page (see the Flickr API)

    PhotoList<Photo> photoList = flickr.getPhotosetsInterface().getPhotos(PHOTOSET_ID, extras, 0, 0, 0);


    //We'll use the direct URL to the original size of the photo in order to download it. Remember: you want to make as few requests from flickr as possible!

    for(Photo photo : photoList){
        //You can also get other sizes. Just ask for the info in the first request.
        URL url = new URL(photo.getOriginalSize().getSource());



        InputStream is = url.openStream();
        OutputStream os = new FileOutputStream(PATH_OF_FOLDER + photo.getTitle() + "." +  photo.getOriginalFormat());

        byte[] b = new byte[2048];
        int length;

        while ((length = is.read(b)) != -1) {
            os.write(b, 0, length);
        }

        is.close();
        os.close();
    }

将此方法用于单张照片输入流。

    InputStream inputStream = flickr.getPhotosInterface().getImageAsStream(flickr.getPhotosInterface().getPhoto(PHOTO_ID), Size.ORIGINAL);

答案 1 :(得分:0)

我对Java和该框架不是很熟悉,但会尝试提供帮助。 我在该框架中找到了下一个方法名称:

public class PeopleInterface {
public static final String METHOD_GET_PHOTOS = "flickr.people.getPhotos";


/**
     * Returns photos from the given user's photostream. Only photos visible the
     * calling user will be returned. this method must be authenticated.
     *
     * @param userId
     * @param extras
     * @param perpage
     * @param page
     * @return
     * @throws IOException
     * @throws FlickrException
     * @throws JSONException
     */
    public PhotoList getPhotos(String userId, Set<String> extras, int perPage,
            int page)

我从下面找到的Flick API文档:

  

flickr.people.getPhotos 从指定用户的照片流中返回照片。仅返回主叫用户可见的照片。   必须验证此方法;为用户返回公开照片,   使用flickr.people.getPublicPhotos。

因此,这意味着您必须通过“读取”权限进行身份验证才能获得您的私人照片(您的帐户)。 如果您是该用户的联系人/朋友,您也可以获得某些用户的私密照片。