【问题标题】:Getting "Error Code 8" When Calling [ACAccountStore requestAccessToAccountsWithType] - iOS Facebook调用 [ACAccountStore requestAccessToAccountsWithType] 时获取“错误代码 8” - iOS Facebook
【发布时间】:2013-05-01 18:39:25
【问题描述】:

我一直在搜索 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}}}

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

【问题讨论】:

  • 运行 iOS 6.0 的 iPod Touch
  • 在“设置”中登录 Facebook 对吧?
  • 是的。我重新安装了官方 Facebook 应用,使用 iOS6 帐户登录 Facebook 应用,Facebook 出现在我的 Setting.app 中 Facebook 部分的应用列表中。
  • 您是否有“活动访问令牌”?
  • 显然不是?我认为这就是requestAccessToAccountsWithType 应该完成的任务?

标签: ios facebook ios6 acaccount acaccountstore


【解决方案1】:

您的选项字典中有错误。

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

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

正确的字典是:

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

或者,声明字典字面量:

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

【讨论】:

  • 谢谢。绝对是那些“太简单了”的问题之一。
  • 在电子邮件选项中我们需要指定任何邮件ID
猜你喜欢
  • 1970-01-01
  • 2013-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-01
  • 1970-01-01
  • 2012-07-11
相关资源
最近更新 更多