本文介绍了如何使用Gmail API与Ruby Google API客户端发送消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



send方法要求'id' '(消息ID或线程ID)..但为什么?
我发送新消息,所以它不应该要求。根据Gmail Api documnetation
其可选。

$ b

  ArgumentError:缺少必需的参数:id。 

第二:

它会返回此消息。

 您的客户发出格式错误或非法请求。 

code

  require'mime'
包含MIME



msg = Mail.new
msg.date = Time.now
msg.subject ='这很重要'
msg.headers.set('Priority','urgent')

msg.body = Text.new('hello,world!', 'plain','charset'=>'us-ascii')
msg.from = {'[email protected]'=> 'Boss Man'}
msg.to = {
'[email protected]'=>无,
'[email protected]'=> 'John Doe',
'[email protected]'=> 'Jane Doe',
}

@email = @ google_api_client.execute(
api_method:@ gmail.users.messages.send(:get),
body_object :{
raw:Base64.urlsafe_encode64(msg.to_s)
},
参数:{
userId:'me'
}

和当然认证工作正常。



其他一些方法也可以正常工作:

 获取列表消息(Users.messages.list)

获取单个消息(Users.messages.get)

但是

发送消息不起作用。

>

  @ gmail.users.messages.send(:get)等于@ gmail.users.messages.get 

因为.send是ruby方法



所以现在这个方法与

  @ gmail.users.messages.to_h ['' GMA il.users.messages.send'] 

示例:

  msg = Mail.new 
msg.date = Time.now
msg.subject =选项[:主题]
msg.body = Text.new(options [:message])
msg.from = {@_user.email => @ _user.full_name}
msg.to = {
options [:to] =>选项[:to_name]
}
@email = @ google_api_client.execute(
api_method:@ gmail.users.messages.to_h ['gmail.users.messages.send'],
body_object:{
raw:Base64.urlsafe_encode64(msg.to_s)
},
参数:{
userId:'me',
}

谢谢。


i'm facing several problem with API,

first:

send method asking for 'id'(message id or thread id) .. but why ? i'm sending new message so it shouldn't require . according to Gmail Api documnetation its optional . https://developers.google.com/gmail/api/v1/reference/users/messages/send

ArgumentError: Missing required parameters: id.

second:

even after specify message id it return this message .

 Your client has issued a malformed or illegal request.

code

 require 'mime'
 include MIME



msg = Mail.new
msg.date = Time.now
msg.subject = 'This is important'
msg.headers.set('Priority', 'urgent')

msg.body = Text.new('hello, world!', 'plain', 'charset' => 'us-ascii')
msg.from = {'[email protected]' => 'Boss Man'}
msg.to   = {
    '[email protected]' => nil,
    '[email protected]' => 'John Doe',
    '[email protected]' => 'Jane Doe',
}

@email = @google_api_client.execute(
    api_method: @gmail.users.messages.send(:get),
    body_object: {
        raw: Base64.urlsafe_encode64(msg.to_s)
    },
    parameters: {
        userId: 'me'
    }
)

and of-course authentication working fine.

some other methods also working fine

like:

get list of messages(Users.messages.list)

get single message(Users.messages.get)

but

send message not working .

解决方案
@gmail.users.messages.send(:get) is equal to @gmail.users.messages.get

because ".send" is ruby method

so now this method is working with

@gmail.users.messages.to_h['gmail.users.messages.send']

example:

msg = Mail.new
msg.date = Time.now
msg.subject = options[:subject]
msg.body = Text.new(options[:message])
msg.from = {@_user.email => @_user.full_name}
msg.to   = {
    options[:to] => options[:to_name]
}
@email = @google_api_client.execute(
    api_method: @gmail.users.messages.to_h['gmail.users.messages.send'],
    body_object: {
        raw: Base64.urlsafe_encode64(msg.to_s)
    },
    parameters: {
        userId: 'me',
    }
)

Thanks.

这篇关于如何使用Gmail API与Ruby Google API客户端发送消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:24