當爲用戶設置手錶時,是否有辦法將手錶限制爲僅添加到收件箱的消息?有沒有辦法將Gmail手錶限制爲僅添加的消息?
根據文檔(https://developers.google.com/gmail/api/v1/reference/users/watch)我看到有INBOX labelId選項,但我想限制它只添加消息。我們現在必須通過在後續history.list調用中的字段字符串中傳遞'history/messagesAdded'來處理此問題。
當爲用戶設置手錶時,是否有辦法將手錶限制爲僅添加到收件箱的消息?有沒有辦法將Gmail手錶限制爲僅添加的消息?
根據文檔(https://developers.google.com/gmail/api/v1/reference/users/watch)我看到有INBOX labelId選項,但我想限制它只添加消息。我們現在必須通過在後續history.list調用中的字段字符串中傳遞'history/messagesAdded'來處理此問題。
不幸的是,您不能。你需要做的是
獲得通知到達時的歷史。歷史記錄返回json
,如果添加新消息,它將包含'messagesAdded'
。
你可以保持predefined array of labels
像下面
predefinedLabels = ['UNREAD', 'CATEGORY_PERSONAL', 'INBOX']
現在你可以檢查,(each is the history json)
if 'messagesAdded' in each:
labels = each["messagesAdded"][0]["message"]["labelIds"]
intersectionOfTwoArrays = list(set(predefinedLabels) & set(labels))
在這裏,你得到intersection of labels
。現在,你必須檢查與predefined labels
if set(predefinedLabels) == set(intersectionOfTwoArrays):
#get the messageId and do what you want
終於可以
filter the notification
只要你想!最好存儲
histroyId
並更新它每notification
並使用它,當你得到history
。它會幫助你 只獲取更新歷史記錄。
請注意我在建造我的服務器時使用了python
。因此,上面的代碼使用python
寫入它看起來像history.list添加了一個新的參數「historyTypes」。如果將其設置爲「messageAdded」,則api將僅返回該類型的歷史記錄。