FaceBook iOS - check if my facebook app is allowed

My question is how to check if my FaceBook application is already allowed for user messages, can not find any information about this.

I use:

Facebook* facebook = [[Facebook alloc] initWithAppId:@"1234567"]; [facebook authorize:[NSArray arrayWithObjects:@"read_stream", @"offline_access",nil] delegate:self]; 

A dialog box appears asking you to authorize the application, when everything is over, everything is in order, you can do:

  [facebook dialog:@"feed" andDelegate:self]; 

to post notes about this app.

But if the user blocks or uninstalls the application, I want to authorize again before showing the dialog for publication, I can’t find a way to get such information before calling the authorization.

Any help is appreciated.

Thanks.

+7
source share
2 answers

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 { //Everything is ok. You can call the dialog method. It should work. } 

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"]) //aha! { //user has unauthorized the app, lets logout from Facebook connect. Also clear the access and expiration date tokens [facebook logout:self]; //Call the authorize method again. Or let the user know they need to authorize the app again. } } } 

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.

+3
source

I'm not sure exactly how to do this using the Facebook SDK, but you can use FQL to query permissions . The request URL will look something like this:

 https://api.facebook.com/method/fql.query?query=SELECT+uid,+read_stream,+offline_access+FROM+permissions+WHERE+uid=me()&access_token=... 

It looks like requestWithMethodName:andParams:andHttpMethod:andDelegate: passes fql.query , since the method is a transition method if you can arrange isSessionValid as true (or somehow supply access_token in the parameters yourself).

0
source

All Articles