facepy icon indicating copy to clipboard operation
facepy copied to clipboard

Getting graph API status code

Open hasandiwan opened this issue 1 year ago • 2 comments

I notice that the return value from graph.post is a CaseInsensitiveDict looking something like:

{'url': 'https://graph.facebook.com/hdiwan/feed', 'type': 'website', 'updated_time': '2023-04-03T20:41:35+0000', 'headers': {'Content-Type': 'application/json; charset=UTF-8', 'Vary': 'Origin', 'cross-origin-resource-policy': 'cross-origin', 'x-app-usage': '{"call_count":3,"total_cputime":0,"total_time":2}', 'x-fb-rlafr': '0', 'Access-Control-Allow-Origin': '*', 'facebook-api-version': 'v16.0', 'Strict-Transport-Security': 'max-age=15552000; preload', 'Pragma': 'no-cache', 'Cache-Control': 'private, no-cache, no-store, must-revalidate', 'Expires': 'Sat, 01 Jan 2000 00:00:00 GMT', 'x-fb-request-id': 'AQXW3Pr67qpWs4QSQODHm4l', 'x-fb-trace-id': 'Ge22de5mzNF', 'x-fb-rev': '1007232980', 'X-FB-Debug': 'QHZDnSMiP5eKYxBkwZQtGxpEslBFpWvNMVck965OTtsBb9EWiKepOBLoq7smeHnArHdZbC0VdPyN4UNNk+0TxA==', 'Date': 'Mon, 03 Apr 2023 20:41:36 GMT', 'Alt-Svc': 'h3=":443"; ma=86400', 'Connection': 'keep-alive', 'Content-Length': '111'}}

How would I know if my call was successful or not?

hasandiwan avatar Apr 03 '23 20:04 hasandiwan

Hey @hasandiwan!

Facepy should throw a FacebookError if it gets a non-200 OK status code, so that's how you'll know. Here's the code that does it: https://github.com/jgorset/facepy/blob/master/facepy/graph_api.py#L102

jgorset avatar Apr 04 '23 17:04 jgorset

There's no exception thrown, but my status isn't updated. Will examine further and update this comment.


EDIT: Examining further, it would seem that you just return the value of request.json, and I'm not sure how to get the status code from that object.

hasandiwan avatar Apr 04 '23 20:04 hasandiwan