Getting “Error Code 8” When Calling [ACAccountStore requestAccessToAccountsWithType] - iOS Facebook

情到浓时终转凉″ 提交于 2019-12-01 05:03:15

问题


I have been searching Google and SO and cannot find what com.apple.accounts Error Code 8 means. I am attempting to use iOS 6 and the Facebook SDK.

I run this request;

  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) {
                                            if (granted) {
                                                NSLog(@"Success");
                                                NSArray *accounts = [_accountStore accountsWithAccountType:fbActType];
                                                _facebookAccount = [accounts lastObject];                                                    
                                            } else {
                                                NSLog(@"ERR: %@",error);
                                                // Fail gracefully...
                                            }
        }
 ];

I get this error:

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

No matter what I do, granted never returns true. Any ideas would be very much appreciated.

If I bypass the if(granted) and call this function:

- (void)me{

    NSLog(@"Home.m - (void)me");

    NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];

    SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                              requestMethod:SLRequestMethodGET
                                                        URL:meurl
                                                 parameters:nil];

    merequest.account = _facebookAccount;

    [merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        NSLog(@"%@", meDataString);

    }];

Then I see this JSON that is returned by Facebook: {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}}

Update: So, the error means "The client's access info dictionary has incorrect or missing values." but I do not know what that means.


回答1:


There is an error in your options dictionary.

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

read better the method declaration: "dictionary with object and keys", so first object, then key...but you have inserted first KEYS and then OBJECTS (wrong order :-)

The correct dictionary is:

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

or, declaring dictionary literal:

    NSDictionary *options = @{
                              ACFacebookAppIdKey : @"###############",
                              ACFacebookPermissionsKey : [NSArray arrayWithObject:@"email"]
                             };


来源:https://stackoverflow.com/questions/16425325/getting-error-code-8-when-calling-acaccountstore-requestaccesstoaccountswitht

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!