Facebook publish HTTP Error 400 : bad request
Question: Hey I am trying to publish a score to Facebook through python's urllib2
library.

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

I am getting this error:

    
    
       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
    

Not sure if this is relating to Facebook's Open Graph or improper urllib2 API
use.


Answer: You may have to provide user:agent as some browser. I remember getting similar
error while running crawler in some website, as it detected that no browser is
calling for it.

