我一直在搜索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}}}
更新:因此,错误意味着“客户端的访问信息字典中包含错误或缺失值”。但我不知道这意味着什么。
答案 0 :(得分:13)
您的选项词典中有错误。
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"]
};