4

我一直在搜索 Google 和 SO,但找不到 com.apple.accounts 错误代码 8 的含义。我正在尝试使用 iOS 6 和 Facebook SDK。

我运行这个请求;

  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...
                                            }
        }
 ];

我收到此错误:

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

无论我做什么,都granted不会返回 true。任何想法将不胜感激。

如果我绕过if(granted)并调用此函数:

- (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);

    }];

然后我看到 Facebook 返回的这个 JSON: {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}}

更新:因此,错误意味着“客户端的访问信息字典的值不正确或缺失”。但我不知道那是什么意思。

4

1 回答 1

13

您的选项字典中有错误。

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

更好地阅读方法声明:“带有对象和键的字典”,所以第一个对象,然后是键......但是你已经插入了第一个键然后是对象(错误的顺序:-)

正确的字典是:

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

或者,声明字典文字:

    NSDictionary *options = @{
                              ACFacebookAppIdKey : @"###############",
                              ACFacebookPermissionsKey : [NSArray arrayWithObject:@"email"]
                             };
于 2013-05-10T19:27:49.860 回答