为什么在使用 todoist python api 时会返回这个奇怪的 ID?

Why is this weird ID returned when using todoist python api?

这个问题是关于todoist的使用python api。

添加项目后(这就是 api 中对任务的称呼),我得到了这些看起来很奇怪的 ID。我说奇怪是因为常规 id 只是一个整数。但是这些 ID 无论如何都不能用,我不能用这个 ID 做 api.items.get_by_id() 。到底是怎么回事?我如何摆脱这种奇怪的状态?

'reply email': 'b5b4eb2c-b28f-11e9-bd8d-80e6500af142',

我又打印了几个 ID,所有整数 ID 都适用于所有 API 调用,UUID 会抛出异常。

3318771761
3318771783
3318771807
3318771823
3318771843
61c30a10-b2a0-11e9-98d7-80e6500af142
62326586-b2a0-11e9-98d7-80e6500af142
62a3ea9e-b2a0-11e9-98d7-80e6500af142
631222ac-b2a0-11e9-98d7-80e6500af142
63816338-b2a0-11e9-98d7-80e6500af142
63efd14c-b2a0-11e9-98d7-80e6500af142

您必须使用 api.commit() 进行同步并获得最终 ID。您尝试使用的 ID 只是同步未完成时的临时 ID。

>>> import todoist; import os; token = os.environ.get('token'); api = todoist.TodoistAPI(token); item=api.items.add('test');

>>> item
Item({'content': 'test',
 'id': '3b4d77c0-b891-11e9-a080-2afbabeedbe3',
 'project_id': 1490600000})

>>> api.commit()
{'full_sync': False, 'sync_status': {'3b4d793c-b891-11e9-a080-2afbabeaeaef': 'ok'}, 'temp_id_mapping': {'3b4d77c0-b891-11e9-a080-2afbabeaeaef': 3331113774}, 'labels': [], 'project_notes': [], 'filters': [], 'sync_token': 'EEVprctG1E39VDqJfu_cwyhpO6rkOaavyU5r70Eu0nY1ZjsWSjssGr4qLLLikucJAu_Zakld7DniBsEyZ7i820dqcZNcOAbUcbzHFpMpSjzr-GALTA', 'day_orders': {}, 'projects': [], 'collaborators': [], 'day_orders_timestamp': '1564672738.25', 'live_notifications_last_read_id': 2259500000, 'items': [{'legacy_project_id': 1484800000, 'day_order': -1, 'assigned_by_uid': 5050000, 'labels': [], 'sync_id': None, 'section_id': None, 'in_history': 0, 'child_order': 3, 'date_added': '2019-08-06T21:29:18Z', 'id': 3331113774, 'content': 'test2', 'checked': 0, 'user_id': 5050000, 'due': None, 'priority': 1, 'parent_id': None, 'is_deleted': 0, 'responsible_uid': None, 'project_id': 1490600000, 'date_completed': None, 'collapsed': 0}], 'notes': [], 'reminders': [], 'due_exceptions': [], 'live_notifications': [], 'sections': [], 'collaborator_states': []}

>>> item
Item({'assigned_by_uid': 5050000,
 'checked': 0,
 'child_order': 3,
 'collapsed': 0,
 'content': 'test',
 'date_added': '2019-08-06T21:29:18Z',
 'date_completed': None,
 'day_order': -1,
 'due': None,
 'id': 3331100000,
 'in_history': 0,
 'is_deleted': 0,
 'labels': [],
 'legacy_project_id': 148400000,
 'parent_id': None,
 'priority': 1,
 'project_id': 1490660000,
 'responsible_uid': None,
 'section_id': None,
 'sync_id': None,
 'user_id': 5050000})