Question

I am writing an android application, which will access a user (functional account)'s photos. If possible even hard coding the functional account id& password would be fine. No end-user interaction is required.

Not able to use the google data api as android don't support So the closest thing I found is this Single-user "installed" client authentication in Gdata API doc, To use ClientLogin (also called "Authentication for Installed Applications"), create a PicasawebService object, then invoke the setUserCredentials method to set the user ID and password

PicasawebService myService = new PicasawebService("exampleCo-exampleApp-1"); 
myService.setUserCredentials("liz@gmail.com", "mypassword");

Picasa Service is Not available in the API console.

Meanwhile, when I try to use the OAuth 2.0 it is not availalbe

I wonder Picasa should be quite popular, what is the best way to do such simple access?

official picasa-atom-oauth sample

This is the official picasa-atom-oauth sample I found. There is a customized call-back server class, however seems it is making use of the browser to get the token. Is it possible to hard code the password in it?

I read this similar question, and seems there is also issue on the token. Did anyone succeed to use "oauth2:https://picasaweb.google.com/data/" as suggested?

Was it helpful?

Solution

Finally after googling more examples, the old client login is the way to go.

I used google api client 1.10.1-beta

  private static String getTokenByAuthenticatingWithClientLogin(HttpTransport transport) throws IOException {
    ClientLogin authenticator = new ClientLogin();
    authenticator.authTokenType = "lh2";
    authenticator.username = "username";
    authenticator.password = "password";
    authenticator.transport = transport;
    return authenticator.authenticate().getAuthorizationHeaderValue();
  }

set the token in headers

GoogleHeaders headers = new GoogleHeaders();
headers.setApplicationName("APOD/1.0");
headers.setGDataVersion("2");
  String token = getTokenByAuthenticatingWithClientLogin(transport);
  headers.setAuthorization(token);

Then use com.google.api.client.http.HttpRequestFactory to construct the request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top