FBSDKLog missing permission

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?

+4
source share
2 answers

To allow publishing inside your application using FBSDK, you must ask the user for additional permissions when logging in: publish_actions

Example:

 [loginManager logInWithPublishPermissions:@[@"publish_actions"]
                         fromViewController:self
                                    handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    //TODO: process error or result.
  }];

Référence:
https://developers.facebook.com/docs/facebook-login/ios

+1

, .

. , facebook , public_actions , https://developers.facebook.com.

, facebook, .

+1

All Articles