龙卷风框架(FacebookGraphMixin) [英] Tornado Framework (FacebookGraphMixin)

查看:99
本文介绍了龙卷风框架(FacebookGraphMixin)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试使用Tornado Framework将我的Facebook应用程序中的应用程序请求发送给用户.我正在关注 http://www.tornadoweb.org/documentation/auth.html ,但是我不知道如何解决此错误.有专业人士吗?谢谢!

I wanted to try sending App request from my Facebook app to a user using Tornado Framework. I was following http://www.tornadoweb.org/documentation/auth.html but I have no idea how to resolve this error. Any professionals out there? Thanks!

错误日志

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()

推荐答案

好的,我的回答不能直接回答OP的问题.但这显示在搜索结果的顶部,显示错误AttributeError: 'XxxxxHandler' object has no attribute 'async_callback'

Okay, my answer does not directly answer the OP's question. But as this shows up in the top search results for the error AttributeError: 'XxxxxHandler' object has no attribute 'async_callback'

值得注意的是,启动Tornado v4.0的async_callback功能已被删除.要引用向后兼容说明:

It is worth noting that starting Tornado v4.0 the async_callback function has been removed. To quote the Backwards-compatibility notes:

RequestHandler.async_callbackWebSocketHandler.async_callback 包装器功能已被删除;他们已经过时了 由于堆栈上下文(以及最近的协程)而导致的时间很长.

The RequestHandler.async_callback and WebSocketHandler.async_callback wrapper functions have been removed; they have been obsolete for a long time due to stack contexts (and more recently coroutines).

这篇关于龙卷风框架(FacebookGraphMixin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆