有没有改变谷歌谈话状态的API?

时间:2013-06-22 21:33:02

标签: ruby google-api xmpp google-talk xmpp4r

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

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

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

When I write status or name, I meen special message 'Bogdan' on this picture

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

2 个答案:

答案 0 :(得分: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)

我爱ruby ^ _ ^!

答案 1 :(得分:0)

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


import xmpp

import dns

class 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()
相关问题