Upload image from android phone to google photos album directly

1.1k Views Asked by At

I've been looking for an API for google photos that will allow me to create an app in android to push up my pictures to a specific album in the cloud. So far, I've seen two possible solutions:

1) the google drive api - I actually developed a POC last night and got it mostly working but unfortunately I can't specify a a google photos album to send my image to.

2) the old picasaweb api - this one looks more promising but I can't get past validating my credentials. Here's a google article describing how to set this up, but the setUserCredentials() method on the PicasawebService object is no longer functional (https://developers.google.com/picasa-web/docs/3.0/developers_guide_java)

I'd like to keep pursuing option 2 a bit but I can't find a method on that PicasawebService object that will allow me to make subsequent calls using a logged in user account on my phone (either by google sign-in or the AccountPicker intent). I thought maybe the setUserToken() method would work and I tried plugging in the tokens I've received from both of the above login methods. I am requesting this in my OAuth2 scope "oauth2:profile email https://picasaweb.google.com/data/" which does indeed prompt me and ask if I want to give access to my photos, I just can't figure out how to tie the logged in user account to PicasawebService calls.

if I hit this URL (this URL is in the article I linked above) from a browser where I'm logged into my google account, I see everything I'd expect to see: https://picasaweb.google.com/data/feed/api/user/username?kind=album so I know that the api is still functional, I just can't figure out how to push up my valid credentials in my android app.

any suggestions would be greatly appreciated TIA

2

There are 2 best solutions below

2
Sam On

I have not personally done this, but take a look at this guy's repo.

https://github.com/tedyk/google-photos-android

Hopefully that gets you going.

1
danny117 On

I had this working at one time back in 2013-2014. But there was too much talk of shutting down picasa web so I never put it into production. Not all the code just the authentication you asked for...Good Luck.

// get the elusive token

if (TextUtils.isEmpty(token)) {
                String SCOPE = "oauth2:http://picasaweb.google.com/data/";
                try {
                    token = GoogleAuthUtil.getToken(context, email, SCOPE);
                } catch (UserRecoverableAuthException e) {
                    token = "";
                } catch (IOException e) {
                    token = "";
                } catch (GoogleAuthException e) {
                    token = "";
                }
                if (TextUtils.isEmpty(token)) {
                    return null;
                }
            }




// send back to picasa
            String urls = "https://picasaweb.google.com/data/entry/api/user/"
                    + userId + "/albumid/" + albumId;
            URL url = new URL(urls);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url
                    .openConnection();
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setDoInput(true);
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setUseCaches(false);
            // clientid may not be necessary is a crazy long string I think you get it from dashboard. it looks like blah.aps.googleusercontent.com
            httpURLConnection.setRequestProperty("X-GData-Client", CLIENT_ID);
            httpURLConnection.setRequestProperty("GData-Version", "2");
            httpURLConnection.setRequestProperty("Authorization", "OAuth "
                    + token);