When sending a post to my feed on Facebook using the /me/feed endpoint, I've gotten different k开发者_如何学Cinds of errors back.
When I sent the same post twice, I got a
400
http status and this error:{"error":{"type":"OAuthException","message":"(#506) Duplicate status message"}}
When the user removed permission to post I got a
400
http status and this error:{"error":{"type":"OAuthException","message":"(#200) The user hasn't authorized the application to perform this action"}}
After the user removed the app I got a
400
http status and this error:{"error":{"type":"OAuthException","message":"Error validating access token: The session has been invalidated because the user has changed the password."}}
I want to be able to reauth the user if he has removed our app or remove permission for us to post. How am I supposed to know? All the errors are returning status code 400
. All the errors are returning type "OAuthException". Some of them have a status code in the message. Is that something I can check for and be guaranteed it will not change? What about the 3rd one? Is that specific error the only one that doesn't have a code? Is there a list of these codes somewhere?
Best way that I have used to validate the user is to check /me to see if any exception is returned. The feed could bring up mixed results, especially if the user hasn't given the application permission to read their feed.
You can also do a method call to users.get to determine what permissions the user has given the application.
Before calling to /me/feed you should verify the users session.
That way you can test to see if they are logged in or not and reroute/send to login accordingly.
The simplest method is to do a GET on /me/feed first and see if you get data or an error.
If an error its a safe bet the authorisation has dropped. And you should get the user to relogin/authorize the App.
The third error, is specific since at this point you know where the user is in the flow. They have logged in and authed, but the access token is either invalid or has run out. Again reauth.
http://developers.facebook.com/docs/authentication/ should help
精彩评论