0

Hi I am new to flickrj library.
Have foundational java knowledge though.
The project that I am working on requires me to authenticate into flickr and then download geo-tagged images into a folder in local hard drive. The program will be Desktop application program.
I am approaching the program by breaking down into 3 steps.



1.Proper authentication to be completed.(which i have succeeded)
2.Try to download all the photos that user has when authenticated.
3.Try to alter the code a little so that it will only download geo-tagged images.

My problems is on step 2. I cant download logged-in user images let alone geo-tagged ones. I am trying the code provided by Daniel Cukier here
But I am running into problem. My netbeans simply strike off at the line 77 on .getOriginalAsStream() part, with the error "java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.io.ByteArrayOutputStream.write"
From my understanding netbeans striking off a line means , it is depreciated but shouldnt it still work? What is holding this whole problem back?

I have tried researching and basically I have to admit , it is beyond my capability to trouble shoot. If anyone has any idea on what i am doing wrong , I would be so grateful.
Ps: I am not looking to be spoon fed but please answer me in idiot-friendly way as I am still a student and my java isn't the greatest.

This code is what I have so far.

import com.aetrion.flickr.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.aetrion.flickr.auth.Auth;
import com.aetrion.flickr.auth.AuthInterface;
import com.aetrion.flickr.auth.Permission;
import com.aetrion.flickr.photos.Photo;
import com.aetrion.flickr.photos.PhotoList;
import com.aetrion.flickr.photos.PhotosInterface;
import com.aetrion.flickr.util.IOUtilities;
import java.io.*;
import java.util.Iterator;
import org.apache.commons.io.FileUtils;


public class authenticate {
Flickr f;
RequestContext requestContext;
String frob = "";
String token = "";
Properties properties = null;

public authenticate() throws ParserConfigurationException, IOException, SAXException {
    InputStream in = null;
    try {
        in = getClass().getResourceAsStream("/setup.properties");
        properties = new Properties();

        properties.load(in);
    } finally {
        IOUtilities.close(in);
    }
    f = new Flickr(
        properties.getProperty("apiKey"),
        properties.getProperty("secret"),
        new REST()
    );
    Flickr.debugStream = false;
    requestContext = RequestContext.getRequestContext();
    AuthInterface authInterface = f.getAuthInterface();
    try {
        frob = authInterface.getFrob();
    } catch (FlickrException e) {
        e.printStackTrace();
    }
    System.out.println("frob: " + frob);
    URL url = authInterface.buildAuthenticationUrl(Permission.DELETE, frob);
    System.out.println("Press return after you granted access at this URL:");
    System.out.println(url.toExternalForm());
    BufferedReader infile =
      new BufferedReader ( new InputStreamReader (System.in) );
    String line = infile.readLine();
    try {
        Auth auth = authInterface.getToken(frob);
        System.out.println("Authentication success");
        // This token can be used until the user revokes it.
        System.out.println("Token: " + auth.getToken());
        System.out.println("nsid: " + auth.getUser().getId());
        System.out.println("Realname: " + auth.getUser().getRealName());
        System.out.println("Username: " + auth.getUser().getUsername());
        System.out.println("Permission: " + auth.getPermission().getType());

        PhotoList list = f.getPhotosetsInterface().getPhotos("72157629794698308", 100, 1);
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
        Photo photo = (Photo) iterator.next();
        File file = new File("/tmp/" + photo.getId() + ".jpg");
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        b.write(photo.getOriginalAsStream());
        FileUtils.writeByteArrayToFile(file, b.toByteArray());
}






    } catch (FlickrException e) {
        System.out.println("Authentication failed");
        e.printStackTrace();
    }
}




public static void main(String[] args) {
    try {
        authenticate t = new authenticate();
    } catch(Exception e) {
        e.printStackTrace();
    }
    System.exit(0);
}

}

Community
  • 1
  • 1
  • Check this out: http://stackoverflow.com/questions/2333285/java-lang-runtimeexception-uncompilable-source-code-what-can-cause-this – nullpotent May 20 '12 at 13:44
  • I have tried the suggestions given. It doesn't seem to work. I think it is the problem with the code rather than the IDE. Thanks for the answer though. – user1406252 May 21 '12 at 02:00
  • I have answered a very similar question on how to successfully set up an authenticated flickrj api instance here, I hope that helps: http://stackoverflow.com/questions/3289552/how-to-access-private-photos-through-flickrj-api/15643638#15643638 – Michelin Man Mar 26 '13 at 17:37

2 Answers2

0

You are correct in your interpretation of the strikeout that getOriginalAsStream() is deprecated. It looks like you might want to rework your code to use PhotosInterface.getImageAsStream(), passing the ORIGINAL size as one of the arguments.

To adjust NetBeans' behavior with respect to deprecated methods, you can follow the link recommended by @AljoshaBre as well as this one.

Community
  • 1
  • 1
David Gorsline
  • 4,933
  • 12
  • 31
  • 36
0

If you want download all your photos from Flickr, this is possible if you have a mac computer.
Download Aperture program on Apple Store and install it.
After to install, open the Aperture.
Go on preferences.
Click on 'Accounts' tab.
Click on plus sign (+) on bottom left to add a photo service.
Add the Flicker option.
Follow the login and authorization instructions.
Done! All your photos will be synchronized in you aperture library locate on ~/images/

I hope I have helped.