I need to publish status on Facebook timeline. My code consists 2 request. First for verifying email permission, second for verifying publish permission. I get successful response with permission "email" request but I get error "Publish permission error: The operation couldn’t be completed. (com.apple.accounts error 8.)" in second case. Do you have any ideas where could be error? Thanks for help.
- (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);
}
}];
}
Okey, I've got it! Options dictionary has to look like this:
NSDictionary *options = @{
ACFacebookAppIdKey : key,
ACFacebookPermissionsKey : @[@"publish_stream", @"publish_actions"],
ACFacebookAudienceKey: ACFacebookAudienceEveryone
};
Instead of this:
NSDictionary *options = @{
ACFacebookAppIdKey : key,
ACFacebookPermissionsKey : @[@"publish_stream"]
};