【问题标题】:Tornado Framework (FacebookGraphMixin)Tornado 框架 (FacebookGraphMixin)
【发布时间】:2012-02-19 00:46:18
【问题描述】:

我想尝试从我的 Facebook 应用向使用 Tornado 框架的用户发送应用请求。我正在关注http://www.tornadoweb.org/documentation/auth.html,但我不知道如何解决此错误。有专业的吗?谢谢!

错误日志

Traceback (most recent call last):
  File "send.py", line 36, in <module>
    main()
  File "send.py", line 33, in main
    test.get(app_access_token, player_id)
  File "send.py", line 15, in get
    callback=self.async_callback(self._on_post))
AttributeError: 'Send' object has no attribute 'async_callback'

代码

import tornado.auth
import tornado.escape
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado import httpclient

class Send(tornado.auth.FacebookGraphMixin):
    def get(self, app_access_token, player_id):
        self.facebook_request(
            "/"+player_id+"/apprequests",
            post_args={"message": "I am an app request from my Tornado application!"},
            access_token=app_access_token,
            callback=self.async_callback(self._on_post))

    def _on_post(self, new_entry):
        if not new_entry:
            # Call failed; perhaps missing permission?
            self.authorize_redirect()
            return
        self.finish("Posted a message!")

def main():
    key = "xxxxxxxxxxx"
    secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    player_id = "100003395454290" #fake id
    http_client = httpclient.HTTPClient()
    response = http_client.fetch("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id="+key+"&client_secret="+secret+"&redirect_uri=&code=")
    app_access_token = response.body.replace("access_token=","")

    test = Send()
    test.get(app_access_token, player_id)

if __name__ == "__main__":
    main()

【问题讨论】:

    标签: python facebook request send tornado


    【解决方案1】:

    好的,我的回答并没有直接回答 OP 的问题。但正如这显示在错误AttributeError: 'XxxxxHandler' object has no attribute 'async_callback'的顶部搜索结果中@

    值得注意的是,从 Tornado v4.0 开始,async_callback 功能已被删除。引用Backwards-compatibility notes

    RequestHandler.async_callbackWebSocketHandler.async_callback 包装函数已被删除;它们已经过时了 由于堆栈上下文(以及最近的协程)而需要很长时间。

    【讨论】:

      【解决方案2】:

      您似乎忘记了对tornado.web.RequestHandler 进行子类化。变化:

      class Send(tornado.auth.FacebookGraphMixin):
      

      收件人:

      class Send(tornado.web.RequestHandler, tornado.auth.FacebookGraphMixin):
      

      【讨论】:

      • 嗨,谢谢罗!但是有没有办法在没有 tornado.web.RequestHandler 的情况下做到这一点?
      • @yori, async_callbacktornado.web.RequestHandler 的一种方法,所以你必须找到一种方法来做到这一点而不使用该方法。
      • 只是想知道...您认为不使用 tornado.web.RequestHandler 是否可行?我的老板说不要使用 tornado.web.RequestHandler :(我有点迷失为什么。
      • @yori,这是你老板的问题!你不能使用tornado.web.RequestHandler 方法,而不继承它们。 =)
      猜你喜欢
      • 2011-07-01
      • 2010-12-27
      • 2010-11-27
      • 2015-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      相关资源
      最近更新 更多