如何使用带有Ruby Google API客户端的Gmail API发送消息?
发布时间:2020-12-17 04:01:53 所属栏目:百科 来源:网络整理
导读:我面临着API的几个问题, 第一: 发送方法询问’id'(消息ID或线程ID)..但为什么? ???我正在发送新消息,所以它不应该要求.根据Gmail Api documnetation ???它是可选的. ???https://developers.google.com/gmail/api/v1/reference/users/messages/send Argumen
我面临着API的几个问题,
第一: 发送方法询问’id'(消息ID或线程ID)..但为什么? ArgumentError: Missing required parameters: id. 第二: 即使在指定消息ID后,它也会返回此消息. Your client has issued a malformed or illegal request. 码 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 = {'hi@gmail.com' => 'Boss Man'} msg.to = { 'list@example.com' => nil,'john@example.com' => 'John Doe','jane@example.com' => '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' } ) 并且当然认证工作正常. 其他一些方法也很好 喜欢: get list of messages(Users.messages.list) get single message(Users.messages.get) 但 发送消息不起作用. 解决方法
我认为
@gmail.users.messages.send(:get) is equal to @gmail.users.messages.get 因为“.send”是ruby方法 所以现在这个方法正在使用 @gmail.users.messages.to_h['gmail.users.messages.send'] 例: 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'],parameters: { userId: 'me',} ) 谢谢. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |