Recently I needed to close a Google Apps account, and I tried to migrate albums programmatically. I’ll document here the needed steps and explain why this Google API is useless for most of us:
First you need an app token, you can get it from Google Console on https://console.developers.google.com. There you need to register your project and associate API from the library.
You should now have both client_id and client_secret so you can fetch the code quite easily with a OAUTH2 flow:
#!/bin/sh $client_id = "foo" $client_secret= "bar" scope="https://www.googleapis.com/auth/photoslibrary+https://www.googleapis.com/auth/photoslibrary.sharing" url="https://accounts.google.com/o/oauth2/auth?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=$scope&response_type=code" echo $url
If you open such output URL with a browser you’ll get the $code and with such code, you can just fetch the tokens.
$code = "lol" curl --request POST --data "code=$code&client_id=$client_id&client_secret=$client_secret&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
With the refresh_code you can already do what you need, here you have an example kotlin script I worked on https://gist.github.com/ivmos/860b5db0ffeeeba8ffd33adebfaaa094
But finally, I just did it manually zooming out from web client. It happens that Google just offers consents that allow you to manipulate photos and albums created with your own app, so you can’t move around photos between albums created by the official too. This means you cannot organize your library automatically unless you just need to work with photos you would upload with your own app…