4

据我了解,当我调用时[ACAccountStore requestAccessToAccountsWithType:options:completion],用户应该会看到一个 UIAlert,询问他们是否授予我的应用程序权限。

当我运行这段代码时,从来没有提示,granted变量总是“假”

-(void)myfunction { 
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) {
                                                NSLog(@"Home.m - getFBDetails - Check 2");
                                                if (granted == YES) {
                                                    NSLog(@"Success");
                                                    NSArray *accounts = [_accountStore accountsWithAccountType:fbActType];
                                                    _facebookAccount = [accounts lastObject];                                                    
                                                    [self me];
                                               } 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.)"

更新:我做了一些测试,如果我使用 using 运行ACAccountTypeIdentifierTwitter,我会提示连接到我的 Twitter 帐户,所以我假设它与我的 Facebook 设置有关......

4

2 回答 2

3

您的选项字典中有反转的对象和键:

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         @"##########",  ACFacebookAppIdKey,
                         [NSArray arrayWithObject:@"email"], ACFacebookPermissionsKey,
                         nil];
于 2013-07-11T11:10:23.877 回答
2

您实际上缺少一个键:ACFacebookAudienceKey。你可以这样改变它:

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

顺便说一句,当您使用 Twitter 时,选项必须是nil.

于 2013-07-08T22:55:37.893 回答