0

我需要在 Facebook 时间线上发布状态。我的代码包含 2 个请求。第一个用于验证电子邮件权限,第二个用于验证发布权限。我通过权限“电子邮件”请求获得成功响应,但在第二种情况下出现错误“发布权限错误:操作无法完成。(com.apple.accounts 错误 8。)”。你有什么想法可能是错误的吗?感谢帮助。

- (void)facebookStatus:(NSString *)identifier {
ACAccountStore *accountStore = [[ACAccountStore alloc]init];

ACAccountType *FBaccountType= [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

NSString *key = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FacebookAppID"];
NSDictionary *options = @{
                          ACFacebookAppIdKey : key,
                          ACFacebookPermissionsKey : @[@"email"]
                          };

[accountStore requestAccessToAccountsWithType:FBaccountType options:options completion:^(BOOL granted, NSError *error) {
     if (granted) {
         NSArray *accounts = [accountStore accountsWithAccountType:FBaccountType];

         if ([accounts count] > 0) {
             ACAccountStore *accountStore = [[ACAccountStore alloc]init];
             ACAccountType *FBaccountType= [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
             NSString *key = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FacebookAppID"];
             NSDictionary *options = @{
                                       ACFacebookAppIdKey : key,
                                       ACFacebookPermissionsKey : @[@"publish_stream"]
                                       };

             [accountStore requestAccessToAccountsWithType:FBaccountType options:options completion:^(BOOL granted2, NSError *error) {
                  if (granted2) {
                      NSLog(@"Publish")
                      ;                          
                  }
                  else {
                      NSLog(@"Publish permission error: %@", [error localizedDescription]);
                      //_publishPermissionsGranted = NO;
                  }

              }];
         }
     }
     else NSLog(@"Nope");

    if (error) {
        if (error.code == 6) {
            NSLog(@"FB Account doesn't exist");
        }
        NSLog(@"Error: %@", error.localizedDescription);
    }
 }];
}
4

1 回答 1

2

好的,我明白了!选项字典必须如下所示:

NSDictionary *options = @{
                                       ACFacebookAppIdKey : key,
                                       ACFacebookPermissionsKey : @[@"publish_stream", @"publish_actions"],
                                       ACFacebookAudienceKey: ACFacebookAudienceEveryone
                                       };

而不是这个:

NSDictionary *options = @{
                                   ACFacebookAppIdKey : key,
                                   ACFacebookPermissionsKey : @[@"publish_stream"]
                                   };
于 2013-09-13T09:20:37.393 回答