We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › flickrj uploading images to Flickr
Page Index Toggle Pages: 1
flickrj uploading images to Flickr (Read 4672 times)
flickrj uploading images to Flickr
Dec 2nd, 2008, 5:40pm
 
Hi,
for some reason there's no good example for uploading images to Flickr. I'm using the flickrj API with poor info in it.

There's no good example so if anyone can post some more info...

best Jan
Re: flickrj uploading images to Flickr
Reply #1 - Dec 3rd, 2008, 11:58am
 
The code I'm using now which gives me IOException.

//Loading image data into byteArray for "up.upload"

byte data[] = loadBytes("2.tif");


f= new Flickr(apiKey,secretKey,rest);

c=f.getContactsInterface();

p=f.getPeopleInterface();

o=f.getPhotosetsInterface();

up=f.getUploader();

   requestContext = RequestContext.getRequestContext();
   Auth auth = new Auth();
   auth.setPermission(Permission.WRITE);
   //auth.setToken("jan");
   requestContext.setAuth(auth);

requestContext.setSharedSecret(secretKey);

UploadMetaData uploadMetaData = new UploadMetaData(); uploadMetaData.setTitle("hello world");


try {


up.upload(data,uploadMetaData);

} catch (FlickrException e) {


e.printStackTrace();

}
Re: flickrj uploading images to Flickr
Reply #2 - Dec 4th, 2008, 5:08pm
 
Keeping my post living this way Wink
Problem is the "token". I can't get the "new frob" inside my code.
When posting:
frob = authInterface.getFrob();
I get a frob, after this it needs to get the "token" from the url, and store it in the frob.

auth.getToken(); results in NULL.
Re: flickrj uploading images to Flickr
Reply #3 - Dec 10th, 2008, 11:50am
 
I "got" it.
The proces is like this.
like all the "Java" examples:
Generate a URL with a generated FROB.
Visit the URL and CHECK the new FROB inside the url.
With this new frob you can somehow get a token of the generated frob is your token.

I could not find anything inside the flickrj api how to automatically fetch the frob or token. For now I used a PHP script. I know it's stupid but it gave me the right TOKEN.

With this token I can upload images.

The php script <http://drewish.com/projects/phlickr/phlickr>

My example:

String apiKey="XXXXXXXXXXXXXXXXXXXX";
String secretKey ="XXXXX";
String token = "XXXXXXXXXXXXXXXXXXX";

Flickr f;
ContactsInterface c;
PeopleInterface p;
PhotosetsInterface o;
Uploader up = new Uploader(apiKey,secretKey);
REST rest;

RequestContext requestContext;

AuthInterface authInterface;
String frob = "";
void setup()  {
byte data[] = loadBytes("2.tif");
size(500, 500);
f= new Flickr(apiKey,secretKey,(new Flickr(apiKey)).getTransport());
up=f.getUploader();
authInterface=f.getAuthInterface();
requestContext = RequestContext.getRequestContext();
requestContext.setSharedSecret(secretKey);

try {
frob = authInterface.getFrob();
println(frob);
URL joep = authInterface.buildAuthenticationUrl(Permission.WRITE, frob);
println(joep.toExternalForm());
System.out.println("Press return after you granted access at this URL:");

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FlickrException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


try {
Auth auth = new Auth();
requestContext.setAuth(auth);
//authInterface.addAuthToken();
auth.setToken(token);
   auth.setPermission(Permission.WRITE);
 System.out.println("Token Is: " + auth.getToken());
System.out.println("Permission for token: " + auth.getPermission());  
f.setAuth(auth);
UploadMetaData uploadMetaData = new UploadMetaData(); uploadMetaData.setTitle("hello world");
up.upload(data,uploadMetaData);

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FlickrException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
Re: flickrj uploading images to Flickr
Reply #4 - Apr 28th, 2009, 8:57pm
 
Thanks for posting your code - it was really helpful when comparing against the AuthExample.java from flickrj.

It was a bit of a pain, but I got flickrj running as well, and without the PHP.

AuthExample.java suspends execution to give the user the chance to authorize the request for a token from the application.

Code:
...
       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");
...


Without the pause from the BufferedReader input, the code just executes and Flickr never passes a token.

A quick hack that worked for me was to replace the BufferedReader portion with a loop-timer that held up Processing long enough for me to authorize the application (using the URL that prints to the console). The code below pauses output for 30 seconds and spits out the Auth response. You can then use the token in your subsequent flickrj calls.

Code:

...
   println(authURL.toExternalForm());

   long t0, t1;
   t0 = millis();
//    println(t0);
   t1 = millis()+30000;
//    println(t1);    
   while (t0 < t1) {
     t0 = millis();
   }
   println("done yet? ...better be");

   Auth auth = authInterface.getToken(frob);

   // This token can be used until the user revokes it.
   println("Token: " + auth.getToken());
   println("nsid: " + auth.getUser().getId());
   println("Realname: " + auth.getUser().getRealName());
   println("Username: " + auth.getUser().getUsername());
   println("Permission: " + auth.getPermission().getType());    
...
Re: flickrj uploading images to Flickr
Reply #5 - Mar 21st, 2010, 5:52am
 
Hey Guys,


This post has got me almost as far as I need to go in order to explore the FlickrJ java implimentation of the Flickr API.  I have a couple of questions if some can help me the last bit.

I too, was using the authentication example provided in the flickrapi-1.2.zip to get me starting in the Eclipse Development environment.

Code:
System.out.println("frob: " + frob);
URL url = authInterface.buildAuthenticationUrl(Permission.DELETE, frob);
System.out.println("Press return after you granted access at this URL:");


My question is - after I get to this point in the code - I enter the URL as PDA described into a browser window and it does take me to a Flickr page where I am asked as my logged in user (tim bright) to authorize the application to use my account.  I believe this is required in order to get the token.

But here is where I am unclear - If I click yes authorize the Flickr website takes me to the webpage registered in my registered app.  The so called Callback URL- I just put a filler site, my own website homepage in their when I was registoring my app.  

When I click authorize I see that the site attempts to go that page - (as it is in the url among other information) - but obviously becuase that particularly webpage isn't set up to receive my frob, api, secret word and whatever else, it also isn't set up to return the token.

So my question is, I guess.  Do I need to build a web page, (in php I suppose) to handle that data and in fact return a token, or is there a simplier way.

It seems that this is perhaps what kleinejan did, but I couldn't access the PHP link on his/her code.

As you can probably tell - I'm a relatively modest programmer.  I haven't even considered the Processing side of the equation yet, but I figure that is relatively straight forward when I have my access sorted out.

Many thanks for your help in advance.
Page Index Toggle Pages: 1