【问题标题】:Python facebook-sdk Graph api access errorPython facebook-sdk Graph api 访问错误
【发布时间】:2012-12-25 17:37:56
【问题描述】:

我正在使用Python facebook-sdk 获取用户在 Facebook 页面中的帖子。

在 facebook Graph api explorer 中,请求进展顺利:

Get .../coldplay/feed?limit=2

在我的程序中,请求:

In [27]: graph = facebook.GraphAPI("...")
In [28]: posts = graph.get_object('coldplay/feed?limit=2') 

报告错误:

GraphAPIError                             Traceback (most recent call last)

/home/ubuntu/<ipython console> in <module>()

/usr/local/lib/python2.7/dist-packages/facebook.pyc in get_object(self, id, **args)
     97     def get_object(self, id, **args):
     98         """Fetchs the given object from the graph."""
---> 99         return self.request(id, args)
    100
    101     def get_objects(self, ids, **args):

/usr/local/lib/python2.7/dist-packages/facebook.pyc in request(self, path, args, post_args)
    296         except urllib2.HTTPError, e:
    297             response = _parse_json(e.read())
--> 298             raise GraphAPIError(response)
    299         except TypeError:
    300             # Timeout support for Python <2.6

如果我在没有“?limit=2”的情况下请求,程序运行良好:

In [45]: graph = facebook.GraphAPI("...")
In [46]: posts = graph.get_object('coldplay/feed')                                        
In [47]: len(posts)
Out[47]: 2

所以我想知道如何提出请求:'.../feed?limit=2' 适用于 Python facebook-sdk?谢谢。

【问题讨论】:

    标签: python facebook-graph-api facebook-access-token


    【解决方案1】:

    您应该提供limit 作为参数而不是对象的一部分。

    get_object 的定义是def get_object(self, id, **args),这意味着您需要提供关键字 args

    在你的情况下:graph.get_object('coldplay/feed', limit=2)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      • 2016-11-15
      • 2014-05-17
      相关资源
      最近更新 更多