예제 #1
0
  public void setup() {
    size(320, 240);

    String[] devices = Capture.list();
    println(devices);
    // Set up the camera.
    //  cam = new Capture(this, 320, 240);
    cam = new Capture(this, width, height, devices[10]);

    // cam.start();
    // Set up Flickr.
    flickr = new Flickr(apiKey, secretKey, (new Flickr(apiKey)).getTransport());

    // Authentication is the hard part.
    // If you're authenticating for the first time, this will open up
    // a web browser with Flickr's authentication web page and ask you to
    // give the app permission. You'll have 15 seconds to do this before the Processing app
    // gives up waiting fr you.

    // After the initial authentication, your info will be saved locally in a text file,
    // so you shouldn't have to go through the authentication song and dance more than once
    authenticate();

    // Create an uploader
    uploader = flickr.getUploader();
  }
예제 #2
0
  // FLICKR AUTHENTICATION HELPER FUNCTIONS
  // Attempts to authneticate with a given token
  public void authenticateWithToken(String _token) {
    AuthInterface authInterface = flickr.getAuthInterface();

    // make sure the token is legit
    try {
      authInterface.checkToken(_token);
    } catch (Exception e) {
      println("Token is bad, getting a new one");
      getAuthentication();
      return;
    }

    auth = new Auth();

    RequestContext requestContext = RequestContext.getRequestContext();
    requestContext.setSharedSecret(secretKey);
    requestContext.setAuth(auth);

    auth.setToken(_token);
    auth.setPermission(Permission.WRITE);
    flickr.setAuth(auth);
    println("Authentication success");
  }
예제 #3
0
  // Goes online to get user authentication from Flickr.
  public void getAuthentication() {
    AuthInterface authInterface = flickr.getAuthInterface();

    try {
      frob = authInterface.getFrob();
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      URL authURL = authInterface.buildAuthenticationUrl(Permission.WRITE, frob);

      // open the authentication URL in a browser
      open(authURL.toExternalForm());
    } catch (Exception e) {
      e.printStackTrace();
    }

    println("You have 15 seconds to approve the app!");
    int startedWaiting = millis();
    int waitDuration = 15 * 1000; // wait 10 seconds
    while ((millis() - startedWaiting) < waitDuration) {
      // just wait
    }
    println("Done waiting");

    try {
      auth = authInterface.getToken(frob);
      println("Authentication success");
      // This token can be used until the user revokes it.
      token = auth.getToken();
      // save it for future use
      saveToken(token);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // complete authentication
    authenticateWithToken(token);
  }