我试图为登录用户创建一条草稿消息,但在运行下面的命令时继续获取错误Missing draft message
require 'google/api_client'
client = Google::APIClient.new
client.authorization.client_id = ENV['GOOGLE_CLIENT_ID']
client.authorization.client_secret = ENV['GOOGLE_CLIENT_SECRET']
client.authorization.grant_type = 'refresh_token'
client.authorization.refresh_token = User.last.refresh_token
token = client.authorization.fetch_access_token!
gmail = client.discovered_api('gmail', 'v1')
params = { 'userId' => 'me', 'draft' => { 'message' => {'raw' => 'test email' } } }
# { 'userId' => 'me', 'message' => {'raw' => 'test email' } }
result = client.execute(api_method: gmail.users.drafts.create, parameters: params)另外,我尝试了对params的注释式组合,但仍然没有运气。有什么想法吗?
发布于 2014-08-25 21:21:13
当我第一次尝试这样做时,我也遇到了同样的问题。我找到的解决方案不是将消息信息作为参数的一部分,而是将其传递到:body_object中,如下所示。
@result = client.execute(
:api_method => gmail.users.drafts.create,
:parameters => {
'userId' => "me"
},
:body_object => {
'message' => {
'raw' => Base64.urlsafe_encode64('Test Email Message')
}
}
)发布于 2014-09-28 10:49:34
raw in message是完整的SMTP消息。
body_object中设置内容message中设置完整的SMTP消息,包括报头。例:
params = { 'userId' => 'me', 'draft' => { 'message' => {'raw' => 'From: foo@example.com\nSubject:Ignore\n\ntest email' } } }https://stackoverflow.com/questions/25493213
复制相似问题