2

I am writing a java app in eclipse that backups data to several consumer-cloud-services encrypted and redundant.

So far, I successfully implemented the authentication process, as it is described in the documentation.

At this point, I do not know how to proceed. The next step would be implementing the auth with the stored AccessToken and afterwars implementing upload/download/listing functionality through the REST API.

  1. I think I have to store the String oauth.getSerialized(). How do I authenticate with this String afterwards? This does not work e.g.:

    AuthenticateResponse oauth = api.authenticate(serialized);
    api.setAuthorizer(new OAuthAuthorizer(oauth));
    
  2. Can someone tell me please, how I can use the REST API with java? There is no explanation or link in the developers area as far as I saw.

And btw, I wasted at least one hour trying to fix errors, because some needed libraries are listet after the example code. :/

user68186
  • 37,795
Michael
  • 21

1 Answers1

1

I managed to solve this.

As you mention you are able to store the auth tokens. So following is the way forward:

Objective: Create the U1FileAPI object

public U1FileAPI(String appPackageName, String appVersion,
    HttpClient httpClient, Authorizer authorizer)

Constructor accepts :

  1. appPackageName >This is same as package name you have given @ the time of authentication creation
  2. appVersion >This is same as appVersion name you have given @ the time of authentication creation
  3. httpClient > create a new one HttpClient httpClient = new DefaultHttpClient();
  4. authorizer > For this you require little effort:

    ObjectInputStream input = new ObjectInputStream(
        new FileInputStream("/file/where/you/save/auth/tokens"));
    

Create the OAuthAuthorizer object:

OAuthAuthorizer aOuth = OAuthAuthorizer.getWithTokens(
    input.readObject().toString(), new HmacSha1MessageSigner());

Now you are good to go for U1FileAPI creation:

U1FileAPI   uOneFs = new U1FileAPI(package_api, version, httpClient, aOuth);

Use the expose methods of uOneFs to solve your actual backup requirements.

While browsing found Cross reference for Ubuntu One, hope it will also help you to understand this better: http://code.metager.de/source/xref/ubuntu/one/files-java-library/src/main/com/ubuntuone/api/files/U1FileAPI.java#resourceClient

Eliah Kagan
  • 119,820
pankaj
  • 11