2012-01-25 7 views
3

FacebookアプリからのアプリリクエストをTornado Frameworkを使用しているユーザーに送信しようとした。私はhttp://www.tornadoweb.org/documentation/auth.htmlをフォローしていましたが、このエラーを解決する方法はわかりません。そこにいる専門家は?ありがとう!Tornado Framework(FacebookGraphMixin)

エラーログ

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

答えて

0

あなたがtornado.web.RequestHandlerをサブクラス化するのを忘れているように見えます。変更:

class Send(tornado.auth.FacebookGraphMixin): 

へ:

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

おかげさまでロブ! しかし、tornado.web.RequestHandlerなしでこれを行う方法はありますか? – yori

+0

@yoriの場合、 'async_callback'は' tornado.web.RequestHandler'のメソッドなので、そのメソッドを使わずに実行する方法を見つけなければなりません。 –

+0

ちょっと疑問...あなたはtornado.web.RequestHandlerを使わずにその可能性を考えていますか?私の上司はtornado.web.RequestHandlerを使用しないように言った:(なぜなら少し失われている。 – yori

1

さて、私の答えは、直接、OPの質問に答えていません。しかし、これがエラーの先頭の検索結果に表示されるので、AttributeError: 'XxxxxHandler' object has no attribute 'async_callback'

これは、Tornado v4.0を起動すると、async_callback機能が削除されていることに注意してください。 Backwards-compatibility notesを引用する:

RequestHandler.async_callbackWebSocketHandler.async_callback ラッパー関数が削除されました。スタックコンテキスト(および最近コルーチン)のために、長い時間が で廃止されました。

関連する問題