使用 GMAIL 从 gmail 的收件箱中删除多封电子邮件 API
Delete multiple emails from INBOX in gmail using GMAIL API
有没有一种方法可以使用 GMAIL API select 来自 gmail 中收件箱的多封电子邮件 API 并在一个请求中删除它们。例如:我已经 select 删除了 3 封邮件,并且只在一个请求中删除了它们。
在 GMAIL API 我找到了这个
service.users().threads().delete(userId, threadId).execute();
其中我必须将邮件的消息ID 逐一传递才能删除,这将耗费大量时间。提前致谢
Gmail 提供 API 一次删除多封电子邮件,您可以在请求正文中传递多个 ID。这是 API 参考。
https://developers.google.com/gmail/api/v1/reference/users/messages/batchDelete
编辑:添加示例代码
我使用 google-api-client v0.8.2 gem 进行了 API 调用。这是示例代码。
require 'google/api_client'
@client = Google::APIClient.new({application_name: 'MyApp', application_version: 'MyAppVersion'})
@client.authorization.access_token = MY_ACCESS_TOKEN
@service = @client.discovered_api('gmail')
payload = {ids: ['id_1', 'id_2']} # You can add multiple ids here
result = @client.execute(
:api_method => @service.users.messages.batch_delete,
:parameters => {userId: 'me'},
:headers => {'Content-Type' => 'application/json'},
:body => payload.to_json
)
puts result.success? # true/false
NOTE: The API used in sample code will not move your messages to trash, rather it will permanently delete your messages.
我喜欢@Sambit 的回答,但对于那些虔诚地使用 python 的人来说,它的 service.users().message().batch Delete(userId=userid).body(jsonIds 即 {'ids':'id', 'id', 'id'}) 花了我一段时间才弄清楚,我希望我能节省一些人的时间
有没有一种方法可以使用 GMAIL API select 来自 gmail 中收件箱的多封电子邮件 API 并在一个请求中删除它们。例如:我已经 select 删除了 3 封邮件,并且只在一个请求中删除了它们。
在 GMAIL API 我找到了这个
service.users().threads().delete(userId, threadId).execute();
其中我必须将邮件的消息ID 逐一传递才能删除,这将耗费大量时间。提前致谢
Gmail 提供 API 一次删除多封电子邮件,您可以在请求正文中传递多个 ID。这是 API 参考。
https://developers.google.com/gmail/api/v1/reference/users/messages/batchDelete
编辑:添加示例代码
我使用 google-api-client v0.8.2 gem 进行了 API 调用。这是示例代码。
require 'google/api_client'
@client = Google::APIClient.new({application_name: 'MyApp', application_version: 'MyAppVersion'})
@client.authorization.access_token = MY_ACCESS_TOKEN
@service = @client.discovered_api('gmail')
payload = {ids: ['id_1', 'id_2']} # You can add multiple ids here
result = @client.execute(
:api_method => @service.users.messages.batch_delete,
:parameters => {userId: 'me'},
:headers => {'Content-Type' => 'application/json'},
:body => payload.to_json
)
puts result.success? # true/false
NOTE: The API used in sample code will not move your messages to trash, rather it will permanently delete your messages.
我喜欢@Sambit 的回答,但对于那些虔诚地使用 python 的人来说,它的 service.users().message().batch Delete(userId=userid).body(jsonIds 即 {'ids':'id', 'id', 'id'}) 花了我一段时间才弄清楚,我希望我能节省一些人的时间