4

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.

Chris
  • 5,485
  • 15
  • 68
  • 130
  • iPod Touch running iOS 6.0 – Chris May 09 '13 at 17:55
  • Logged into FaceBook in Settings, right? – Undo May 09 '13 at 17:56
  • Yes. I re-installed the official Facebook app, logged into the Facebook app using the iOS6 account, and the Facebook appeared in my Setting.app within the list of apps in the Facebook section. – Chris May 09 '13 at 17:57
  • Do you have an 'active access token'? – Undo May 09 '13 at 17:57
  • Apparently not? I assume that is what `requestAccessToAccountsWithType` is supposed to accomplish? – Chris May 09 '13 at 17:59
  • Are you using `FBSession` anywhere? – Undo May 09 '13 at 18:02
  • In fact, are you using the Facebook API *from FaceBook* (not built-in iOS) at all? – Undo May 09 '13 at 18:03
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29685/discussion-between-chris-and-undo) – Chris May 09 '13 at 18:06
  • possible duplicate of [iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert](http://stackoverflow.com/questions/16469077/ios-requestaccesstoaccountswithtype-is-not-showing-permission-prompt-nsalert) – WrightsCS Sep 20 '13 at 19:44

1 Answers1

13

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"]
                             };
LombaX
  • 17,265
  • 5
  • 52
  • 77