I also had to deal with this problem.
When you call the dialog method, you send a delegate that must match the FBDialogDelegate, which has a method that is called when the dialog does not load due to an error. But in the case when the application was unauthorized, a dialog box displays the userβs login screen, but after setting the user and password, a second form appears, allowing the user to know that an error has occurred. The delegate is also called, but the error received states that the method failed without any specific reason or even error number. This method must be called with the correct error before anything, so that the application can act accordingly.
So, I found a job, maybe this is not the best way, but it certainly works. Any call you make to the api schedule on Facebook through a request will fail if the application was unauthorized by the user. So I did this to test this before calling the feed's dialog method.
Add the following line where you need to check if the application is allowed:
if ([facebook isSessionValid]) //isSessionValid only checks if the access token is set, and the expiration date is still valid. Lets make a call and see if we really are authorized to post to this user from this app. [facebook requestWithGraphPath:@"me" andDelegate:self]; else //authorize Facebook connect
This will call a method that returns basic information from the user. If everything is in order, the following method is called from the delegate:
- (void)request:(FBRequest *)request didLoad:(id)result {
If the application was unauthorized by the user, the following method will be called from the delegate:
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error; { NSString *type = [[[error userInfo] objectForKey:@"error"] objectForKey:@"type"]; if (type) { if ([type isEqualToString:@"OAuthException"])
So, as I said, not the best way, but it does its job. We hope that Facebook will add a method to test this particular scenario or add a new method to the delegate who deals with the problem of unauthorized use.
carlos
source share