0

我正在实现一个应用程序,用户可以在其中发布状态。如果用户是他/她设备中的默认登录名,则以下代码将起作用

  if(!self.accountStore)
    self.accountStore = [[ACAccountStore alloc] init];
if(NSClassFromString(@"SLComposeViewController") != nil)
{
    ACAccountType *facebookTypeAccount = [self.accountStore 
    accountTypeWithAccountTypeIdentifier:@"com.apple.facebook"];
    NSLog(@"facebookTypeAccount..:%@",facebookTypeAccount);
    NSArray *accounts = [self.accountStore accountsWithAccountType:facebookTypeAccount];
    if (facebookTypeAccount) {
        if ([accounts respondsToSelector:@selector(count)]) {
            [self.accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                                       options:@{ACFacebookAppIdKey: @"214267482030378", ACFacebookPermissionsKey: @[@"email"]}
                                                    completion:^(BOOL granted, NSError *error) {
                                                        if(granted){
                                                            NSArray *accounts = [self.accountStore accountsWithAccountType:facebookTypeAccount];
                                                            _facebookAccount = [[accounts lastObject]retain];
                                                        }
                                                        else
                                                        {
                                                            NSLog(@"Failed, Error: %@", error);
                                                        }
                                                    }];
        }
        else
        {
            [self openSession];
        }
    }
} 

否则控制将转到此方法

- (void)openSession{
NSArray *permissions = [[NSArray alloc] initWithObjects:
                        @"publish_stream",@"email",
                        nil];
[FBSession openActiveSessionWithPublishPermissions:permissions
                                   defaultAudience:FBSessionDefaultAudienceEveryone
                                      allowLoginUI:YES
                                 completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
 {
     [self sessionStateChanged:session state:state error:error];

 }];

}

但是登录后我需要在 Facebook 上发送状态。如果我尝试使用这种方法

   -(void)poststatus{
[[FBSession activeSession] reauthorizeWithPublishPermissions:@[ @"publish_stream" ]  
defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession 
*authSession, NSError *authError) {
    // If auth was successful, create a status update FBRequest
    if (!authError) {
        FBRequest *postRequest = [FBRequest requestForPostStatusUpdate:@"Hello, world!"];
        [postRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            // TODO: Check for success / failure here
        }];
    }
}];

}

然后它给出错误失败,错误:错误域 = com.apple.accounts 代码 = 8“操作无法完成。(com.apple.accounts 错误 8。)”如果有人有一些想法请帮助我这个概念。

提前致谢。

4

1 回答 1

1

要求:

@[@"publish_stream", @"publish_actions"]

而不仅仅是:

@[ @"publish_stream" ]

阅读更多: https ://developers.facebook.com/docs/reference/login/extended-permissions/

publish_stream  The publish_stream permission is required to post to a Facebook Page's timeline. For a Facebook User use publish_actions.

此外,您正在使用已弃用的功能。尝试:

[FBSession requestNewPublishPermissions:defaultAudience:completionHandler:];
于 2013-10-08T09:42:36.057 回答