Skip to content

Instantly share code, notes, and snippets.

@kosho
Created May 7, 2015 00:47
Show Gist options
  • Save kosho/e1357471fd667f6ef072 to your computer and use it in GitHub Desktop.
Save kosho/e1357471fd667f6ef072 to your computer and use it in GitHub Desktop.
Delete all Picasa albums created by the user
# Delete all Picasa albums created by the user
# Note: Autogenerated albums such as Auto Backup and Instant Upload can not be deleted
# Your Google Account to manage
GOOGLE_ACCOUNT=<REPLACE_WITH_YOURS>
# Your Gooel Developer API Credentials
# Go to https://console.developers.google.com to register your project
CLIENT_ID=<REPLACE_WITH_YOURS>
CLIENT_SECRET=<REPLACE_WITH_YOURS>
RET=$(curl -d "client_id=$CLIENT_ID&scope=http://picasaweb.google.com/data/ profile" https://accounts.google.com/o/oauth2/device/code)
VERIFICATION_URL=$(echo $RET | sed -e 's/.*\"verification_url\" : "\(.*\)\",.* \"expires.*/\1/')
USER_CODE=$(echo $RET | sed -e 's/.*\"user_code\" : "\(.*\)\",.* \"verification.*/\1/')
DEVICE_CODE=$(echo $RET | sed -e 's/.*\"device_code\" : "\(.*\)\",.* \"user.*/\1/')
echo Open $VERIFICATION_URL with your web browser and type in "$USER_CODE" to authorize the script. Come back to this screen and hit [ENTER] key once done.
read Wait
RET=$(curl -d "client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&code=$DEVICE_CODE&grant_type=http://oauth.net/grant_type/device/1.0" https://accounts.google.com/o/oauth2/token)
ACCESS_TOKEN=$(echo $RET | sed -e 's/.*\token\" : \"\(.*\)\", \"token_type.*/\1/')
RET=$(curl -H "Authorization: Bearer $ACCESS_TOKEN" https://picasaweb.google.com/data/feed/api/user/$GOOGLE_ACCOUNT)
ALBUM_URLS=`echo $RET | xmllint --format - | grep "rel=\"edit\"" | sed -e 's/.*href=\"\(.*\)\".*/\1/'`
declare -i counter=0
for URL in $ALBUM_URLS ; do
echo "Deleting: $URL"
curl -X DELETE -H "Authorization: Bearer $ACCESS_TOKEN" "$URL"
((counter++))
done
echo "Done. $counter album(s) deleted."
@kosho
Copy link
Author

kosho commented May 7, 2015

delete_picasa_albums

Delete all Picasa albums created by the user other than auto generated albums such as Auto Backup and Instant Upload.
Open delete_picasa_albums.sh and fulfill necessary information marked as <REPLACE_WITH_YOURS>.

Note: You must register your own project to retrieve Google API credentials. See https://console.developers.google.com for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment