Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error ACErrorPermissionDenied (error code 7) for Facebook when using Social Framework

I am fetching the user’s Facebook account ID and name using ACAccountStore.

When an alert comes up asking the user for permission (“XYZ would like to access your news feed and profile”) and the user taps on “Don’t Allow”, I get error code 7, i.e ACErrorPermissionDenied.

But after that, if I go to Settings and switch on the Facebook settings for my app and back in the app the alert pops up again and the user taps on “OK”, I’m still getting error code 7 (ACErrorPermissionDenied). So it’s enabled in Settings and I’ve tapped “OK” in the app, but it’s still giving me this error.

If the first time I allow access and after that switch access on or off from Settings, it gives me the proper error or success. This problem occurs only if the user taps “Don’t Allow” the first time. If he doesn’t allow it in the app when it asks, then he will not be able to allow FB access to my app.

I’ve tested this on iOS 6.0 and 6.0.1 using the following code:

 NSMutableArray *acAccountArray = [[NSMutableArray alloc] init];

ACAccountStore *accountStore = [[ACAccountStore alloc] init];

ACAccountType *accountType =
[accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

[accountStore
 requestAccessToAccountsWithType:accountType
 options:[self getOptionDictionary:ACAccountTypeIdentifierFacebook permission:[[NSArray alloc]initWithObjects:@"read_stream",@"user_about_me",@"email", nil]]
 completion:^(BOOL granted, NSError *error) {
     if(granted) {
         // Doing what I want

     } else {
         NSLog(@"Error: %@", error);
     }
 }];



-(NSDictionary *)getOptionDictionary:(NSString * const)accountTypeIdentifier
                      permission:(NSArray*)permissionArray {
NSDictionary *options = nil;
if (accountTypeIdentifier == ACAccountTypeIdentifierFacebook) {
    options = @{
    @"ACFacebookAppIdKey" : @"dhksadhakjdhkshd",
    @"ACFacebookPermissionsKey" : permissionArray,
    @"ACFacebookAudienceKey" : ACFacebookAudienceFriends};
}
return options;}
like image 956
Bhagyashree Dayama Avatar asked Nov 12 '22 13:11

Bhagyashree Dayama


1 Answers

Is your app still in "sandbox mode" on Facebook? If yes, it will be visible only to administrators and developers. If you're logged in to Facebook on your device with a non-administrator for your app, you might receive this error. Disabling the sandbox mode fixed the problem for me.

like image 199
bes Avatar answered Nov 15 '22 05:11

bes