我正在尝试在我的网络服务(AppEngine Python)中使用 Facebook 聊天 API。我在网上找到了一些代码,但它们中的任何一个都可以帮助我使其工作。
这是我正在使用的代码,但不起作用。我做错了什么?
class TestHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'application/json'
response = dict()
msg = "hello world"
jid = "myID@chat.facebook.com"
pwd = "passwd"
server = "chat.facebook.com"
recipient="targetID@chat.facebook.com"
try:
jid = xmpp.protocol.JID(jid)
cl = xmpp.Client(jid.getDomain(), debug=["always"])
if not cl.connect((server, 5222)):
response['Error Connection'] = 'Not connected.'
elif cl.auth(jid.getNode(), pwd) == None:
response['Error Auth'] = 'Authentication failure.'
else:
cl.send(xmpp.protocol.Message(recipient, msg, "chat"))
cl.disconnect()
response['status'] = 'success'
except:
response['status'] = 'failed'
self.response.out.write(json.dumps(response))