質問

It is my understanding that when I invoke [ACAccountStore requestAccessToAccountsWithType:options:completion], the user is supposed to see an UIAlert that asks them if they grant permission to my app.

When I run this code, there is never a prompt and the granted variable is always "false"

-(void)myfunction { 
if (!_accountStore) _accountStore = [[ACAccountStore alloc] init];

    ACAccountType *fbActType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];


    NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                             (NSString *)ACFacebookAppIdKey, @"##########",  
                             (NSString *)ACFacebookPermissionsKey, [NSArray arrayWithObject:@"email"],  
                             nil];


    [_accountStore requestAccessToAccountsWithType:fbActType options:options completion:^(BOOL granted, NSError *error) {
                                                NSLog(@"Home.m - getFBDetails - Check 2");
                                                if (granted == YES) {
                                                    NSLog(@"Success");
                                                    NSArray *accounts = [_accountStore accountsWithAccountType:fbActType];
                                                    _facebookAccount = [accounts lastObject];                                                    
                                                    [self me];
                                               } else {
                                                    NSLog(@"ERR: %@ ",error);
                                                    // Fail gracefully...
                                              }
            }
     ];

}

And I get the Error: ERR: Error Domain=com.apple.accounts Code=8 "The operation couldn’t be completed. (com.apple.accounts error 8.)"

Update: I did some testing and if I run with using ACAccountTypeIdentifierTwitter, I get the prompt to connect to my Twitter accounts, so I am supposing it is something with my Facebook settings ...

役に立ちましたか?

解決

You have inverted objects and keys in your options dictionary :

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         @"##########",  ACFacebookAppIdKey,
                         [NSArray arrayWithObject:@"email"], ACFacebookPermissionsKey,
                         nil];

他のヒント

You are actually missing a key: ACFacebookAudienceKey. You can change it like that:

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                                 (NSString *)ACFacebookAppIdKey, @"##########",  
                                 (NSString *)ACFacebookPermissionsKey, [NSArray arrayWithObject:@"email"],
                                 (NSString *)ACFacebookAudienceKey, ACFacebookAudienceEveryone,
                                 nil];

By the way, when you are using Twitter, the options must be nil.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top