Reputation: 926
I've tried some suggestions from similar questions etc. None of it helped my situation.
I'm using Facebook.py Licensed under the Apache License in Google App Engine with Python solution.
I've the GraphAPI object created with the valid access token which was mine. And it was shown in App Engine log:
Graph >>> facebook.GraphAPI object at 0x64cc19e10b2ceb90
So, having GraphAPI object created,
graph.put_object('Valid Facebook User ID', "feed",
message="Hello world", link="http://example.com")
This is throwing error log as such:
HTTP Error 400: Bad Request:
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
handler.get(*groups)
File "/base/data/home/apps/s~/development.358229427391780612/handler/profile_handlers.py", line 401, in get
graph.put_object(self.user.user_id, "feed", message="Hello world", link="http://example.com")
File "/base/data/home/apps/s~/development.358229427391780612/facebook.py", line 129, in put_object
return self.request(parent_object + "/" + connection_name, post_args=data)
File "/base/data/home/apps/s~/development.358229427391780612/facebook.py", line 181, in request
file = urllib2.urlopen(graphUrl, post_data)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 124, in urlopen
return _opener.open(url, data)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 425, in error
return self._call_chain(*args)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 506, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 400: Bad Request
Initially, I was putting a lot of additional data as attachment (link, description etc.). However, after reducing the attachment elements, still it's throwing same errors. And also, I was using the method of put_wall_post. Some suggested to use put_object instead.
Tried searching a lot in forums, but still couldn't solve the problems for some of the suggestions.
Any idea what's the main problem ?
Upvotes: 2
Views: 1371
Reputation: 926
I've solved the posted problem on my own. For those who are still trying to solve this and may encounter the same possible error, let me share the solution.
As earlier I do not know nor aware that the permission we asked from user, was only granted for basic access information.
Due to the original solution of facebook.py:
if response.get("error"):
raise GraphAPIError(response["error"]["type"],
response["error"]["message"])
Raising custom exception is always bad as it does not reflect the real exception and thus making debugging triple harder. The original custom exception provided raised following exception:
HTTP Error 400: Bad Request
which often related to bad URL form etc.
Hence, suspecting on that, I changed the exception to:
if response.get("error"):
raise
With this, it will raise the actual exception that it catches:
HTTP Error 403: Forbidden
By having the real exception, I quickly suspected, the authorization problem or Facebook user permission. So, to solve this,:
FB.login(function(response) {
// handle the response
}, {scope: 'publish_actions'});
Here you go, the problem should be solved for exception that raises HTTP Error 403: Forbidden. Cheeeerssss !
Upvotes: 1