龙卷风框架(FacebookGraphMixin)

3
我想尝试使用Tornado Framework从我的Facebook应用程序向用户发送应用请求。 我正在遵循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()
2个回答

1

好的,我的回答并不直接回答OP的问题。但是由于这个错误出现在顶部搜索结果中,因此值得注意的是,从Tornado v4.0开始,async_callback函数已被删除。引用向后兼容性说明

RequestHandler.async_callbackWebSocketHandler.async_callback包装函数已被删除;由于堆栈上下文(最近还有协程)的存在,它们已经过时很长时间。


0
看起و‌¥ن½ ه؟کè®°ن؛†ç»§و‰؟`tornado.web.RequestHandler`م€‚ن؟®و”¹ن¸؛ï¼ڑ
class Send(tornado.auth.FacebookGraphMixin):

至:

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

嘿,谢谢 Rob!但是有没有一种不使用tornado.web.RequestHandler的方法来完成这个? - yori
@yori,async_callbacktornado.web.RequestHandler的一个方法,所以你必须找到一种不使用该方法的方式来完成它。 - Rob Wouters
只是想知道...你觉得可以不使用tornado.web.RequestHandler吗?我的老板说不要用tornado.web.RequestHandler :( 我有点迷茫为什么。 - yori
@yori,这是你的老板问题!如果没有继承tornado.web.RequestHandler,你不能使用它的方法。=) - Nikolay Fominyh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接