我想编写一个应用程序,它将:
- 接收和发送电子邮件(我知道,我可以用 使用 RoR 的 ActionMailer )
- 与我的 Google+ 好友聊天
- 更改我的 GoogleTalk (gmail) 状态
因此,当我打开 Gmail 界面时,我会在页面左侧看到包含我的联系人的列表。我可以与此列表中的人打开聊天,我可以更改状态和名称(靠近我的小 google+ 头像)。
是否存在一些用于更改 google-talk 状态的 Google API(特殊消息)?我可以使用一些 RubyOnRails gem 来实现吗? 谢谢。
最佳答案
所以,这行漂亮的 ruby 代码(使用 xmpp4r gem ), 更改您的 google_talk 状态并向您的 friend 发送 chat_message。 谢谢你,@Arkan!
require 'xmpp4r'
# init jabber client
client_jid = Jabber::JID.new( '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1d8ced4d3fec4ccc0c8cde1c6ccc0c8cd8fc2cecc" rel="noreferrer noopener nofollow">[email protected]</a>' )
client = Jabber::Client.new( client_jid )
client.connect 'talk.google.com'
client.auth 'your_gmail_password'
# change google_talk status
client.send( Jabber::Presence.new.set_show( :chat ).set_status( 'Your New GoogleTalk status' ) )
# send chat_message to friend
friend = Jabber::JID.new("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="037a6c76715c65716a666d675c666e626a6f43646e626a6f2d606c6e" rel="noreferrer noopener nofollow">[email protected]</a>")
message = Jabber::Message::new(friend, "it's chat message").set_type(:normal).set_id('1')
client.send(message)
我喜欢 ruby ^_^!
关于ruby - 有没有可以更改 google-talk 状态的 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17255522/