【问题标题】:are there any APIs for changing google-talk status?是否有用于更改 google-talk 状态的 API?
【发布时间】:2013-06-19 18:46:10
【问题描述】:

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

    所以,这段漂亮的 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)
    

    我爱红宝石^_^!

    【讨论】:

    • 您只能从另一个 google 帐户查看您更新的 GoogleTalk 状态!!!否则,您会自动将状态更改为以前的状态,通过您的网络界面进行配置。
    • 如果您想使用您的 gmail 联系人,请在测试您的代码之前同步您的谷歌设备。否则,您可能有两个联系人与一封电子邮件。例如,您的 gmail 联系人中的“James Alan Hetfield”,但手机中的“James Hetfield”。谷歌第一次会认为这是两个不同的人;)
    【解决方案2】:

    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()
    

    【讨论】:

    • 抱歉,这是什么语言?请给我一些文档和示例的链接。是否有一些适用于 ruby​​ 的 XMPP 适配器?
    • @bmalets,它是 python。看看这个。可能会帮助你:gist.github.com/jpr5/941931
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-26
    相关资源
    最近更新 更多