Reputation: 4439
Anybody else having trouble with adding labels to notes in gkeepapi
?
import gkeepapi
keep = gkeepapi.Keep()
file = open("C:\\xxxxxxx", "r")
pwd = file.read()
keep.login('xxxxxxxx', pwd)
note = keep.createNote('title', 'text')
note.labels.add('calls')
Is giving me this error.
Traceback (most recent call last):
File "C:/Users/Jason/Google Drive/pycharm/test.py", line 8, in <module>
note.labels.add('calls')
File "C:\Python27\lib\site-packages\gkeepapi\node.py", line 922, in add
self._labels[label.id] = label
AttributeError: 'str' object has no attribute 'id'
Here is the docs. https://gkeepapi.readthedocs.io/en/latest/#manipulating-labels-on-notes. I think I'm doing the right thing, but I'm obviously not.
Upvotes: 1
Views: 457
Reputation: 3032
Have you try syncing?
gkeepapi automatically pulls down all notes after login. It takes care of refreshing API tokens, so there’s no need to call Keep.login() again. After making any local modifications to notes, make sure to call Keep.sync() to update them on the server!:
keep.sync()
Upvotes: 0
Reputation: 881653
I would say just about every bug in the history of computers was caused by someone with the thought "I think I'm doing the right thing" in their head :-)
More seriously, the label that you add to a note is meant to be label rather than a string. That's supported by the fact that it's trying to get your label identifier from a string object (which doesn't have one):
'str' object has no attribute 'id'
This is actually described in the link you provided, just three sections up from your anchor point:
Creating Labels
New labels can be created withKeep.createLabel()
:
label = keep.createLabel('todo')
: : blah blah blah
Manipulating Labels on Notes
When working with labels and notes, the key point to remember is that we’re always working withnode.Label
objects or IDs.
Hence you can create a label and add it to the note with the lines:
callLabel = keep.createLabel('calls')
note.labels.add(callLabel)
If you already have a label with that name, you can get it with:
callLabel = keep.findLabel('calls')
So, if you wanted to handle both possibilities seemlessly, try to create the label inside a try/catch
and, if you get an exception, do the find.
Upvotes: 3