简体   繁体   中英

Get private photos using flickrj-android

I am using the open source library: https://code.google.com/p/flickrj-android/ and there is an example how do I get photos from flickr. Main problem is that I get only public photos. How can I manage getting private streams/photos? Did anyone managed to get private streams?

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

I'm not very familiar with Java and that framework but will try to help. I found next method name in that framework:

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)

From Flick API docs I found next:

flickr.people.getPhotos Return photos from the given user's photostream. Only photos visible to the calling user will be returned. This method must be authenticated; to return public photos for a user, use flickr.people.getPublicPhotos.

So, it mean that you must be authenticated with 'read' permissions to get your private pohotos (your account). You can also get private photos of some users only in case if you are contact/friend of that user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM