我有一个问题,我是初学者,我尝试制作一个简单的异步程序来发布到 facebook,我使用tornado 示例和tornado-facebook-sdk,这里是代码:
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)
因为我想了解这个例子来获取token,然后使用例子:
def callback(response):
# ...
graph.put_object('me', 'feed', message="Maoe!!", callback=callback)
为了在我的 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(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 时,我看到它是我正在使用的验证密钥,我什至使用生成的令牌(这里是a
变量),并将其粘贴到 Api Debug,我得到了一切正常:
Valid : True
Origin : Web
Scopes : create_note photo_upload publish_actions publish_stream read_stream share_item status_update video_upload