获取“错误代码8”当呼叫[ACAccountStore requestAccessToAccountsWithType] - iOS Facebook [英] Getting "Error Code 8" When Calling [ACAccountStore requestAccessToAccountsWithType] - iOS Facebook

查看:262
本文介绍了获取“错误代码8”当呼叫[ACAccountStore requestAccessToAccountsWithType] - iOS Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我运行此请求;

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

我收到此错误:

code> ERR:Error Domain = com.apple.accounts Code = 8操作无法完成(com.apple.accounts错误8。)

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

无论我做什么,授予永远不会返回true。任何想法都将非常感激。

No matter what I do, granted never returns true. Any ideas would be very much appreciated.

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

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

    }];

然后我看到Facebook返回的JSON:
{error:{message:必须使用活动的访问令牌来查询当前用户的信息,type:OAuthException,code:2500}}}

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.

推荐答案

您的选项字典中有错误。

There is an error in your options dictionary.

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

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

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

正确的字典是:

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

或声明字典文字:

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

这篇关于获取“错误代码8”当呼叫[ACAccountStore requestAccessToAccountsWithType] - iOS Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆