2012-10-07 23 views
0

我有一個問題,是一個beginer,我要儘量使該帖子給Facebook,我用的是tornado exampletornado-facebook-sdk一個簡單的異步程序,這裏是代碼:不能獲得Facebook的龍捲風連接

class MainHandler(BaseHandler, tornado.auth.FacebookGraphMixin): 
    @tornado.web.authenticated 
    @tornado.web.asynchronous 
    def get(self): 
     self.facebook_request("/me/home", self.print_callback, access_token=self.current_user["access_token"]) 
     a = self.current_user["access_token"] 
     #print a 

    def print_callback(data): 
     print data 
     ioloop.stop() 
     graph.get_object('/facebook', callback=print_callback) 

和我得到這個錯誤:

TypeError: print_callback() takes exactly 1 argument (2 given) 

,因爲我想了解這個例子中獲得令牌,然後使用例如:

def callback(response): 
    # ... 
graph.put_object('me', 'feed', message="Maoe!!", callback=callback) 

要在我的臉書的牆上寫點東西,我用the synchronous library做了,但可惜這是封鎖!

UPDATE:仍然獲取和錯誤:

class MainHandler(BaseHandler, tornado.auth.FacebookGraphMixin): 
    @tornado.web.authenticated 
    @tornado.web.asynchronous 
    def get(self): 
     self.facebook_request("/me/home", self.print_callback, access_token=self.current_user["access_token"]) 
     a = self.current_user["access_token"] 
     print a 

    def print_callback(self, data): 
     graph.post_wall(self, "heloooooooo") 

,並得到這個錯誤:

[E 121009 14:28:47 web:1108] Uncaught exception GET/(::1) 
HTTPRequest(.....) 
Traceback (most recent call last): 
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\web.py", line 1043, in _stack_context_handle_exception 
    raise_exc_info((type, value, traceback)) 
    File "C:\Python27\lib\site-packages\tornado-2.4.post1 py2.7.egg\tornado\stack_context.py", line 237, in _nested 
    yield vars 
    File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\stack_context.py", line 210, in wrapped 
    callback(*args, **kwargs) 
    File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\gen.py", line 405, in inner self.set_result(key, result) 
    File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\gen.py", line 335, in set_result 
    self.run() 
    File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\gen.py", line 365, in run 
    yielded = self.gen.send(next) 
    File "build\bdist.win-amd64\egg\facebook\graphapi.py", line 129, in _make_request 
    raise GraphAPIError(data) 
GraphAPIError: (#200) This API call requires a valid app_id. 

,當我去給Facebook,我看到它是我使用的Valide關鍵,我甚至使用生成的令牌(這裏是a變量),並粘貼到Api調試,我得到一切正常:

Valid : True 
Origin : Web 
Scopes : create_note photo_upload publish_actions publish_stream read_stream share_item status_update video_upload 

回答

1

self加到print_callback

def print_callback(self, data): 
    print data 
    ioloop.stop() 
    graph.get_object('/facebook', callback=print_callback) 
+0

所以這是着名的「明確比實施更好」;) 謝謝 –