尝试使用 Gmail 的 Ruby API 修改标签时出现“未指定标签添加或删除错误”

jas*_*onm 3 ruby gmail-api

我看过https://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/GmailV1/ModifyThreadRequest和示例https://developers.google.com/gmail/api /v1/reference/users/labels/update适用于 Python 和 JS,但无法弄清楚如何在 ruby​​ 中正确格式化请求。

我想:

service.modify_thread('me',thread_id,{'add_label_ids'=>['UNREAD']})
Run Code Online (Sandbox Code Playgroud)

以及对象的各种其他排列,但除了Google::Apis::ClientError: invalidArgument: No label add or removes specified响应之外无法获得任何东西。

任何帮助表示赞赏

per*_*won 6

modify_threadGoogle::Apis::GmailV1::ModifyThreadRequest根据文档,期望一个对象作为第三个参数。

在ModifyThreadRequest 的构造函数的源代码中,您可以看到它:add_label_ids在其参数中寻找一个键。

因此,如果modify_thread创建 ModifyThreadRequest 对象本身,则

service.modify_thread('me',thread_id, add_label_ids: ['UNREAD'])
Run Code Online (Sandbox Code Playgroud)

应该管用。如果失败,我会尝试

mtr = Google::Apis::GmailV1::ModifyThreadRequest.new(add_label_ids: ['UNREAD'])
service.modify_thread('me', thread_id, mtr)
Run Code Online (Sandbox Code Playgroud)