Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何检索Google Talk用户状态消息_Python_Xmpp_Google Talk - Fatal编程技术网

Python 如何检索Google Talk用户状态消息

Python 如何检索Google Talk用户状态消息,python,xmpp,google-talk,Python,Xmpp,Google Talk,我希望能够用Python检索用户Google Talk状态消息,很难找到关于如何使用某些库的文档。我没有安装xmpp的任何资料,但这里有一些旧代码可能对您有所帮助。出于测试目的,您需要将用户名/密码更新为自己的值 注意事项:登录到Google Talk的用户在其用户ID上获得一个随机存在字符串:如果您试图获取其他用户的状态,这并不重要,但是如果您想编写一些代码以便与自己通信,则需要将登录的用户从GMail或GTalk客户端与测试程序区分开来。因此,代码通过用户ID进行搜索 此外,如果您在登录后立

我希望能够用Python检索用户Google Talk状态消息,很难找到关于如何使用某些库的文档。

我没有安装xmpp的任何资料,但这里有一些旧代码可能对您有所帮助。出于测试目的,您需要将用户名/密码更新为自己的值

注意事项:登录到Google Talk的用户在其用户ID上获得一个随机存在字符串:如果您试图获取其他用户的状态,这并不重要,但是如果您想编写一些代码以便与自己通信,则需要将登录的用户从GMail或GTalk客户端与测试程序区分开来。因此,代码通过用户ID进行搜索

此外,如果您在登录后立即读取状态,您可能不会得到任何信息。代码中有一个延迟,因为状态变为可用状态需要一段时间

"""Send a single GTalk message to myself"""

import xmpp
import time

_SERVER = 'talk.google.com', 5223
USERNAME = 'someuser@gmail.com'
PASSWORD = 'whatever'


def sendMessage(tojid, text, username=USERNAME, password=PASSWORD):
    jid = xmpp.protocol.JID(username)
    client = xmpp.Client(jid.getDomain(), debug=[])
    #self.client.RegisterHandler('message', self.message_cb)
    if not client:
      print 'Connection failed!'
      return
    con = client.connect(server=_SERVER)
    print 'connected with', con
    auth = client.auth(jid.getNode(), password, 'botty')
    if not auth:
      print 'Authentication failed!'
      return
    client.RegisterHandler('message', message_cb)
    roster = client.getRoster()
    client.sendInitPresence()
    if '/' in tojid:
        tail = tojid.split('/')[-1]
        t = time.time() + 1
        while time.time() < t:
            client.Process(1)
            time.sleep(0.1)
            if [ res for res in roster.getResources(tojid) if res.startswith(tail) ]:
                break
        for res in roster.getResources(tojid):
            if res.startswith(tail):
                tojid = tojid.split('/', 1)[0] + '/' + res

    print "sending to", tojid
    id = client.send(xmpp.protocol.Message(tojid, text))
    t = time.time() + 1
    while time.time() < t:
        client.Process(1)
        time.sleep(0.1)
    print "status", roster.getStatus(tojid)
    print "show", roster.getShow(tojid)
    print "resources", roster.getResources(tojid)
    client.disconnect()

def message_cb(session, message):
    print ">", message

sendMessage(USERNAME + '/Talk', "This is an automatically generated gtalk message: did you get it?")
“给我自己发送一条GTalk消息”
导入xmpp
导入时间
_服务器='talk.google.com',5223
用户名=someuser@gmail.com'
密码='whatever'
def sendMessage(tojid,文本,用户名=用户名,密码=密码):
jid=xmpp.protocol.jid(用户名)
client=xmpp.client(jid.getDomain(),debug=[])
#self.client.RegisterHandler('message',self.message\u cb)
如果不是客户:
打印“连接失败!”
返回
con=client.connect(服务器=_服务器)
打印“已连接”,con
auth=client.auth(jid.getNode(),密码为'botty')
如果未授权:
打印“身份验证失败!”
返回
client.RegisterHandler('message',message_cb)
花名册=client.get花名册()
client.sendInitPresence()
如果tojid中的“/”:
tail=tojid.split('/')[-1]
t=time.time()+1
而time.time()”,消息
sendMessage(用户名+'/Talk',“这是自动生成的gtalk消息:您收到了吗?”)

我手头没有安装xmpp的任何东西,但这里有一些我手头的旧代码,可能会对您有所帮助。出于测试目的,您需要将用户名/密码更新为自己的值

注意事项:登录到Google Talk的用户在其用户ID上获得一个随机存在字符串:如果您试图获取其他用户的状态,这并不重要,但是如果您想编写一些代码以便与自己通信,则需要将登录的用户从GMail或GTalk客户端与测试程序区分开来。因此,代码通过用户ID进行搜索

此外,如果您在登录后立即读取状态,您可能不会得到任何信息。代码中有一个延迟,因为状态变为可用状态需要一段时间

"""Send a single GTalk message to myself"""

import xmpp
import time

_SERVER = 'talk.google.com', 5223
USERNAME = 'someuser@gmail.com'
PASSWORD = 'whatever'


def sendMessage(tojid, text, username=USERNAME, password=PASSWORD):
    jid = xmpp.protocol.JID(username)
    client = xmpp.Client(jid.getDomain(), debug=[])
    #self.client.RegisterHandler('message', self.message_cb)
    if not client:
      print 'Connection failed!'
      return
    con = client.connect(server=_SERVER)
    print 'connected with', con
    auth = client.auth(jid.getNode(), password, 'botty')
    if not auth:
      print 'Authentication failed!'
      return
    client.RegisterHandler('message', message_cb)
    roster = client.getRoster()
    client.sendInitPresence()
    if '/' in tojid:
        tail = tojid.split('/')[-1]
        t = time.time() + 1
        while time.time() < t:
            client.Process(1)
            time.sleep(0.1)
            if [ res for res in roster.getResources(tojid) if res.startswith(tail) ]:
                break
        for res in roster.getResources(tojid):
            if res.startswith(tail):
                tojid = tojid.split('/', 1)[0] + '/' + res

    print "sending to", tojid
    id = client.send(xmpp.protocol.Message(tojid, text))
    t = time.time() + 1
    while time.time() < t:
        client.Process(1)
        time.sleep(0.1)
    print "status", roster.getStatus(tojid)
    print "show", roster.getShow(tojid)
    print "resources", roster.getResources(tojid)
    client.disconnect()

def message_cb(session, message):
    print ">", message

sendMessage(USERNAME + '/Talk', "This is an automatically generated gtalk message: did you get it?")
“给我自己发送一条GTalk消息”
导入xmpp
导入时间
_服务器='talk.google.com',5223
用户名=someuser@gmail.com'
密码='whatever'
def sendMessage(tojid,文本,用户名=用户名,密码=密码):
jid=xmpp.protocol.jid(用户名)
client=xmpp.client(jid.getDomain(),debug=[])
#self.client.RegisterHandler('message',self.message\u cb)
如果不是客户:
打印“连接失败!”
返回
con=client.connect(服务器=_服务器)
打印“已连接”,con
auth=client.auth(jid.getNode(),密码为'botty')
如果未授权:
打印“身份验证失败!”
返回
client.RegisterHandler('message',message_cb)
花名册=client.get花名册()
client.sendInitPresence()
如果tojid中的“/”:
tail=tojid.split('/')[-1]
t=time.time()+1
而time.time()”,消息
sendMessage(用户名+'/Talk',“这是自动生成的gtalk消息:您收到了吗?”)

您可以使用谷歌API列表签出。您可以使用谷歌API列表签出。