I want to share news with facebook. Here is the code:
RACSignal *sign = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
if([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]){
NSLog(@"1 blck");
NSLog(@"curr tok? %@", [FBSDKAccessToken currentAccessToken]);
[subscriber sendNext:@YES];
[subscriber sendCompleted];
} else {
NSLog(@"2 blck");
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
login.loginBehavior = FBSDKLoginBehaviorWeb;
[login logInWithPublishPermissions:@[@"publish_actions"] fromViewController:APP.window.rootViewController handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
NSLog(@"log passed by");
self.isExecuting = YES;
if (error) {
NSError *err = [NSError errorWithDomain:@"ru.myServer.fb" code:-3 userInfo:@{NSLocalizedDescriptionKey:error.localizedDescription}];
[subscriber sendError:err];
} else if (result.isCancelled) {
NSError *err = [NSError errorWithDomain:@"ru.myServer.fb" code:-4 userInfo:@{NSLocalizedDescriptionKey:@""}];
[subscriber sendError:err];
} else {
NSString *strToken = result.token.tokenString;
NSString *strUserId = result.token.userID;
NSDictionary *dctProps = @{@"token":strToken, @"user_id":strUserId};
[subscriber sendNext:dctProps];
[subscriber sendCompleted];
}
}];
}
It's quite simple, even if you are not familiar with Reactive Cocoa.
For some reason, this code works (publish news) for one account that was allowed earlier, but when I try to share news for another acc, it completes the block, but sends an error
FBSDKLog: warning: access token does not have permission to publish
. Obviously there is no news.
Why is this happening?
source
share