2

我想编写一个应用程序,它将:

  • 接收和发送电子邮件(我知道,我可以使用 RoR 使用 ActionMailer 来完成)
  • 与我的 Google+ 朋友聊天
  • 更改我的 GoogleTalk (gmail) 状态

所以,当我打开我的 gmail 界面时,我会在页面左侧看到我的联系人列表。我可以打开与此列表中的人的聊天,我可以更改状态和名称(靠近我的小 google+ 头像)。

当我写下身份或姓名时,我会在这张照片上添加特殊信息“Bogdan”

是否存在一些用于更改 google-talk 状态(特殊消息)的 Google API?我可以使用一些 RubyOnRails 宝石来做到这一点吗?谢谢。

4

2 回答 2

2

因此,这些漂亮的 ruby​​ 代码行(使用 xmpp4r gem),更改您的 google_talk 状态并将 chat_message 发送给您的朋友。谢谢你,@Arkan!

require 'xmpp4r'

# init jabber client
client_jid = Jabber::JID.new( 'your_email@gmail.com' )
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("your_friend_email@gmail.com")    
message = Jabber::Message::new(friend, "it's chat message").set_type(:normal).set_id('1')
client.send(message)

我爱红宝石^_^!

于 2013-06-24T11:50:41.463 回答
0

Gtalk 的 Xmpp 实现。更改状态 这可能会对您有所帮助。


导入 xmpp

导入 dns

类 Gtalk():

def __init__(self,bot_id,bot_pwd): 
    self.bot_id = bot_id
    self.bot_pwd = bot_pwd
def connect(self):                           
    self.jid = xmpp.protocol.JID(self.bot_id)
    self.presnc = xmpp.protocol.Presence()
    self.conn = xmpp.Client(self.jid.getDomain(),debug=[])
    if self.conn.connect():
        print 'connected..'
        self.auth()
    else:
        print 'err to connect'
def auth(self): 
    if self.conn.auth(self.jid.getNode(),self.bot_pwd):
        self.conn.sendInitPresence()
        print 'Authenticated..'
    else:
        print 'err to authenticate'
def setStatus(self,value):
    self.conn.send(xmpp.protocol.Presence(status=value))
def invisible(self,username):
    self.conn.send(xmpp.protocol.Presence(username,typ='unavailable'))
def visible(slef,username):
    self.conn.send(xmpp.protocol.Presence(username,typ=None))
def disconnect(self):
    self.conn.disconnect()
于 2013-06-24T08:04:49.603 回答