0

嘿,我正在尝试通过 python 的 urllib2 库向 Facebook 发布分数。

import urllib2,urllib

url = "https://graph.facebook.com/USER_ID/scores"
data = {}
data['score']=SCORE
data['access_token']='APP_ACCESS_TOKEN'
data_encode = urllib.urlencode(data)
request = urllib2.Request(url, data_encode)
response = urllib2.urlopen(request)
responseAsString = response.read()

我收到此错误:

   response = urllib2.urlopen(request)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 124, in urlopen
    return _opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 389, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 502, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 427, in error
    return self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 361, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 510, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request

不确定这是否与 Facebook 的 Open Graph 或不正确的 urllib2 API 使用有关。

4

2 回答 2

0

您可能必须提供 user:agent 作为某些浏览器。我记得在某些网站上运行爬虫时遇到了类似的错误,因为它检测到没有浏览器在调用它。

于 2012-06-28T09:14:04.093 回答
0

我运行了你的代码并得到了同样的错误(正文中没有更多的错误,会在评论中发布但我猜还不能)所以我用谷歌搜索“发布 facebook 分数”。

我相信您需要先授予您的应用发布分数的权限,除非您已经这样做了。请参阅http://developers.facebook.com/blog/post/539/

于 2012-06-29T04:52:18.820 回答