Google 保留:gkeepapi -> 无法添加标签
Google Keep: gkeepapi -> can't add labels
还有人在为 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')
给我这个错误。
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'
这是文档。 https://gkeepapi.readthedocs.io/en/latest/#manipulating-labels-on-notes。我认为我在做正确的事,但我显然不是。
我想说的是,计算机历史上几乎 每个 错误都是由头脑中有 "I think I'm doing the right thing" 想法的人造成的:-)
更严重的是,您添加到笔记的标签应该是 label 而不是字符串。它试图从字符串对象(没有字符串对象)获取标签标识符这一事实支持了这一点:
'str' object has no attribute 'id'
这实际上在您提供的 link 中有所描述,距您的锚点仅三节:
Creating Labels
New labels can be created with Keep.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 with node.Label
objects or IDs.
因此您可以创建一个标签并将其添加到带有以下行的注释中:
callLabel = keep.createLabel('calls')
note.labels.add(callLabel)
如果您已经有一个具有该名称的标签,您可以通过以下方式获取它:
callLabel = keep.findLabel('calls')
因此,如果您想无缝地处理这两种可能性,请尝试在 try/catch
中创建标签,如果遇到异常,请进行查找。
还有人在为 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')
给我这个错误。
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'
这是文档。 https://gkeepapi.readthedocs.io/en/latest/#manipulating-labels-on-notes。我认为我在做正确的事,但我显然不是。
我想说的是,计算机历史上几乎 每个 错误都是由头脑中有 "I think I'm doing the right thing" 想法的人造成的:-)
更严重的是,您添加到笔记的标签应该是 label 而不是字符串。它试图从字符串对象(没有字符串对象)获取标签标识符这一事实支持了这一点:
'str' object has no attribute 'id'
这实际上在您提供的 link 中有所描述,距您的锚点仅三节:
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.
因此您可以创建一个标签并将其添加到带有以下行的注释中:
callLabel = keep.createLabel('calls')
note.labels.add(callLabel)
如果您已经有一个具有该名称的标签,您可以通过以下方式获取它:
callLabel = keep.findLabel('calls')
因此,如果您想无缝地处理这两种可能性,请尝试在 try/catch
中创建标签,如果遇到异常,请进行查找。