This project is read-only.

AccessTokenManager class is missing in version 5.0.1

Jul 20, 2013 at 9:23 PM
In version 4 of the library, I am using AccessTokenManager.ValidateAccessToken to check if access token is valid. Is there any replacement of this in version 5.0.1?
Jul 20, 2013 at 9:56 PM
You can simply catch the OAuthException error when calling any API that requires an access token. This avoids the overhead of making a dummy API call to Facebook just to verify the token.
try{
    var u = new ComputerBeacon.Facebook.Graph.User("me","invalid_token");
}
catch(ComputerBeacon.Facebook.OAuthException ex){
    //oops! error happened...
}
Jul 20, 2013 at 11:22 PM
kayson wrote:
You can simply catch the OAuthException error when calling any API that requires an access token. This avoids the overhead of making a dummy API call to Facebook just to verify the token.
try{
    var u = new ComputerBeacon.Facebook.Graph.User("me","invalid_token");
}
catch(ComputerBeacon.Facebook.OAuthException ex){
    //oops! error happened...
}
It is not dummy call, because using ValidateAccessToken, I know why is access token invalid (AccessTokenValidationResult) and take appropriate action.
Jul 21, 2013 at 8:17 AM
I see. It is considered a dummy call because nothing is actually requested from Facebook: it is better to capture the error while making a real API call.

I will integrate this into the OAuthException class shortly, but for the time being I think this will do:
try {
      Execute("Graph Api - User", GraphApi);
}
catch (ComputerBeacon.Facebook.OAuthException ex) {
       if(ex.Message.Contains("Session has expired")) Console.WriteLine("Session expired");
       else if(ex.Message.Contains("has not authorized application")) Console.WriteLine("Not Authorized");
       else if(ex.Message=="Error validating access token: The session has been invalidated because the user has changed the password.") Console.WriteLine("Password changed");
      else if(ex.Message=="Error validating access token: The session is invalid because the user logged out.") Console.WriteLine("User logged out");
      else Console.WriteLine("Unknown error");
}
Jul 21, 2013 at 12:36 PM
kayson wrote:
I see. It is considered a dummy call because nothing is actually requested from Facebook: it is better to capture the error while making a real API call.

I will integrate this into the OAuthException class shortly, but for the time being I think this will do:
try {
      Execute("Graph Api - User", GraphApi);
}
catch (ComputerBeacon.Facebook.OAuthException ex) {
       if(ex.Message.Contains("Session has expired")) Console.WriteLine("Session expired");
       else if(ex.Message.Contains("has not authorized application")) Console.WriteLine("Not Authorized");
       else if(ex.Message=="Error validating access token: The session has been invalidated because the user has changed the password.") Console.WriteLine("Password changed");
      else if(ex.Message=="Error validating access token: The session is invalid because the user logged out.") Console.WriteLine("User logged out");
      else Console.WriteLine("Unknown error");
}
Validating something based on returned string is the worst practice, but using .NET Reflector I see, that it is made same way in version 4. Lets hope that they will never change that text or localize it.
Jul 21, 2013 at 2:42 PM
Edited Jul 21, 2013 at 2:42 PM
I absolutely agree that using the return string to distinguish the result is not a good idea. However, Facebook does not provide different error codes for the error (they are all error 190 with HTTP 400). Usually I will just re-direct the user to the Auth dialog no matter what caused the error, this is one reason I cut the class in the new version.