Reputation: 3479
I am using Facebook Python's SDK along with Google App Engine, and making a call to do a checkin:
graph.put_object("me", "checkins", message="Hello, world", place="165039136840558", coordinates='{"latitude":"38.2454064", "longitude":"-122.0434404"}')
However, this throws an error 400 Bad Request and I don't seem to be able to try catch it so I can have the important information.
On a bad request, Facebook should return, an object like below which can help troubleshoot and address the issue, but I am not sure how I can retrieve this object:
{
"error": {
"type" : "OAuthException",
"message" : "An active access token must be used to query information about the current user."
}
}
[Edit]
I am temporarily able to figure out the issue by: Logging the Post Data
logging.info("LOG" + str(post_data))
and then using a REST client like the extension for Firefox to make the request again. The response gives me the information I need to proceed. However, it would have been better if I can obtain the error messages within my app.
Upvotes: 0
Views: 1421
Reputation: 101
I came across the same issue, and here is how to get that error message:
import urllib2
url='https://graph.facebook.com/me/?method=post' # this will 400 b/c it has no auth token.
try:
resp = urllib2.urlopen(url)
except urllib2.HTTPError as e:
error_reason = e.read()
Then you can use the json
module to examine the JSON Facebook sends with an error:
json_error = json.loads(error_reason)
Make sure you use json.loads
, since error_reason
is a string
Upvotes: 1
Reputation: 363
Like the error says, you need to create and consume an access token: Here's some more info. Sorry I can't "comment" yet and am forced to answer. http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/
Upvotes: 2