how to send message using Gmail API with Ruby Google API Client?

后端 未结 2 1065
野的像风
野的像风 2020-12-10 19:32

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

2条回答
  •  旧巷少年郎
    2020-12-10 20:18

    I think

    @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.

提交回复
热议问题