Facebook聊天API-Python应用程序引擎
我正在尝试在我的web服务(AppEngine Python)中使用Facebook聊天API。我在网上找到了一些代码,但它们中的任何一个都能帮助我使它工作 这是我正在使用的代码,但不起作用。我做错了什么Facebook聊天API-Python应用程序引擎,python,facebook,google-app-engine,xmpp,facebook-chat,Python,Facebook,Google App Engine,Xmpp,Facebook Chat,我正在尝试在我的web服务(AppEngine Python)中使用Facebook聊天API。我在网上找到了一些代码,但它们中的任何一个都能帮助我使它工作 这是我正在使用的代码,但不起作用。我做错了什么 class TestHandler(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'application/json'
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))
我不知道FacebookAPI,但可能你必须把FacebookID放在收件人targetId上。 您必须输入要发送消息的用户ID 收件人=”facebookUserID@chat.facebook.com“当然,我把“targetID”改成了我的朋友ID,在“passwd”中我把密码放在了facebook上,在“myID”中我把我的ID改成了FB中的ID