Skip to content

Instantly share code, notes, and snippets.

@sming
Last active April 18, 2024 11:44
Show Gist options
  • Save sming/06791824d45d0005c883f716f1af0067 to your computer and use it in GitHub Desktop.
Save sming/06791824d45d0005c883f716f1af0067 to your computer and use it in GitHub Desktop.
Simple script that exports Google Keep notes to a file called export-google-keep.py in the current directory
import keyring
import gkeepapi
################################################################
# Simple script that exports Google Keep notes to a file called
# export-google-keep.py in the current directory. A note will
# look like this:
# Hearthstone want list 2,☑ Aggro Druid common’s : Mark of the Lotus, power of the wild
# Rogue eviscerate, cold blood,
#
# Which, you'll notice, is no good for importing - so help appreciated!
################################################################
# gkeepapi.node.DEBUG = True
print("Booting keep...")
keep = gkeepapi.Keep()
username = '<GOOGLE USER NAME>'
# See https://support.google.com/accounts/answer/185833?hl=en to generate
# your app password.
pw = '<GOOGLE APP PASSWORD>'
print("Logging in (be patient - this can take up to 2 minutes)...")
keep.login(username, pw)
print("getting token...")
token = keep.getMasterToken()
print("setting keyring...")
keyring.set_password('google-keep-token', username, token)
print("getting all notes...")
gnotes = keep.all()
print("opening file...")
myfile = open('google-keep-notes.csv', 'w')
print("writing out to file...")
for note in gnotes:
myfile.write(note.title + "," + note.text + "\n")
print("done - closing file...")
myfile.close()
print("done.")
@chaoscreater
Copy link

Getting this error:

gkeepapi.exception.LoginException: ('NeedsBrowser', 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.')

I'm definitely using the correct app password. If I wasn't, I'd get a different error. I've set up 2 different Google Keep backup solutions using other Github projects and they all worked fine, but then recently they broke because of the exact same error. I think perhaps something is changed on Google's side.

@etahamad
Copy link

Getting this error:

gkeepapi.exception.LoginException: ('NeedsBrowser', 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.')

I'm definitely using the correct app password. If I wasn't, I'd get a different error. I've set up 2 different Google Keep backup solutions using other Github projects and they all worked fine, but then recently they broke because of the exact same error. I think perhaps something is changed on Google's side.

I will look into it tomorrow

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