0

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

4

2 回答 2

1

With Flickrj-android you'd want to use this method:

 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();
    }

Use this method for a single-photo inputstream.

    InputStream inputStream = flickr.getPhotosInterface().getImageAsStream(flickr.getPhotosInterface().getPhoto(PHOTO_ID), Size.ORIGINAL);
于 2013-08-16T15:12:01.410 回答
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。

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

于 2013-08-16T13:50:00.987 回答