2013-05-07 43 views
4

我一直在搜索Google和SO,並找不到com.apple.accounts錯誤代碼8的含義。我正在嘗試使用iOS 6和Facebook SDK。當調用[ACAccountStore requestAccessToAccountsWithType]時獲取「錯誤代碼8」 - iOS Facebook

我運行此請求;

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

    }]; 

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

更新:所以,錯誤的意思是」客戶端訪問信息字典的值不正確或缺失。「但我不知道這意味着什麼。

+0

在設備或SIM? – Undo 2013-05-09 17:53:12

+0

運行iOS 6.0的iPod Touch – Chris 2013-05-09 17:55:03

+0

在設置中登錄到FaceBook,對不對? – Undo 2013-05-09 17:56:09

回答

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"] 
          }; 
+0

謝謝。絕對是其中一個「這太簡單」的問題。 – Chris 2013-05-11 15:05:35

+0

在電子郵件選項中,我們需要指定任何郵件ID – 2014-06-18 14:27:11