0

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

Blair Holmes
  • 1,521
  • 2
  • 22
  • 35

2 Answers2

0

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.

Sam
  • 5,342
  • 1
  • 23
  • 39
  • this solution is for google drive integration (see #1 I listed in my OP). It's close, but unfortunately as I said, it doesn't allow for putting photos directly into albums which is my biggest requirement. – Blair Holmes Sep 21 '17 at 17:07
  • oh gotcha, bummer sorry couldn't be of more help. – Sam Sep 21 '17 at 17:09
0

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);
danny117
  • 5,581
  • 1
  • 26
  • 35
  • thanks for the response. I did end up getting this to work a long time ago and just forgot to update this thread. My post parameters are a little different than yours as all of my stuff is wrapped up in the header. `connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization","Bearer "+token); connection.setRequestProperty("Content-Type","image/jpeg"); connection.setRequestProperty("Slug",fileName);` – Blair Holmes Jun 13 '18 at 15:53