【问题标题】:Facebook Chat API - Python App EngineFacebook 聊天 API - Python App Engine
【发布时间】:2013-05-14 04:27:49
【问题描述】:

我正在尝试在我的网络服务 (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))

【问题讨论】:

    标签: python facebook google-app-engine xmpp facebook-chat


    【解决方案1】:

    我不知道 facebook api,但可能您必须将 facebook Id 放在收件人 targetId 上。 您必须输入要发送消息的用户 ID。

    recipient="facebookUserID@chat.facebook.com"

    【讨论】:

    • 当然,我将“targetID”更改为我的朋友 ID,并在“passwd”中将密码输入 facebook,在“myID”中将密码更改为 FB 中的 ID
    猜你喜欢
    • 2011-07-30
    • 2011-07-09
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    相关资源
    最近更新 更多