首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tornado框架(FacebookGraphMixin)

Tornado框架(FacebookGraphMixin)
EN

Stack Overflow用户
提问于 2012-01-26 03:59:50
回答 2查看 1K关注 0票数 3

我想尝试从我的Facebook应用程序向使用Tornado Framework的用户发送应用程序请求。我一直在关注http://www.tornadoweb.org/documentation/auth.html,但是我不知道如何解决这个错误。外面有专业人士吗?谢谢!

错误日志

代码语言:javascript
复制
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'

代码

代码语言:javascript
复制
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()
EN

回答 2

Stack Overflow用户

发布于 2016-03-15 21:37:04

好吧,我的答案并没有直接回答操作员的问题。但是在错误AttributeError: 'XxxxxHandler' object has no attribute 'async_callback'的顶部搜索结果中显示了以下内容

值得注意的是,在启动TornadoV4.0时,async_callback函数已被删除。引用Backwards-compatibility notes

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

票数 1
EN

Stack Overflow用户

发布于 2012-01-26 04:51:57

看起来你忘了继承tornado.web.RequestHandler的子类。更改:

代码语言:javascript
复制
class Send(tornado.auth.FacebookGraphMixin):

至:

代码语言:javascript
复制
class Send(tornado.web.RequestHandler, tornado.auth.FacebookGraphMixin):
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9009406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档