Facebook SDK 4.0: View Publications

I use FBSDKLoginButton to login via Facebook in my application. Well, I define readPermations as:

NSArray *permissions = [NSArray arrayWithObjects:@"public_profile", @"email",nil];
self.loginFbBtn.readPermissions = permissions;

Above all is good. But now, if I need to ask permission for a message on my timeline and want to access the permissions of " publish_actions ", is there a way to set them without actually provoking FBSDKLoginManager , because this is the only way given in Facebook docs :

if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
  // TODO: publish content.
} else {
  FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
  [loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    //TODO: process error or result.
  }];
}

Apparently, this is the only way to call publish_actions for your application. I want to use it without FBSDKLoginManager . Please help, I need this pitching.

SO THIS UPDATE:

Using Wizkid and MingLi, I completed its implementation using FBSDKLoginManager , and the following code segments to enter Facebook through a user button and it @selector(facebookLogin), and then sharing permissions when sharing is required using the method getSharingPermissions:

-(void) facebookLogin
{
    @try
    {
        self.loginManager = [[FBSDKLoginManager alloc] init];
        [self.loginManager setLoginBehavior:FBSDKLoginBehaviorWeb];
        [self.loginManager logInWithReadPermissions:@[@"public_profile",@"email"] handler:^(FBSDKLoginManagerLoginResult *result,NSError *error)
        {
            if([FBSDKAccessToken currentAccessToken])
            {
                [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
                 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
                 {
                     if (!error)
                     {
                         NSLog(@"fetched user:%@", result);
                         NSDictionary *userDict = (NSDictionary*)result;
                     }
                 }];
            }}];
    }
}
@catch (NSException *exception)
{
    NSLog(@"Exception %@", exception);
}

Get sharing permissions:

-(void)getSharePermissions
{
    if (![[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
    {
        [self.loginManager setLoginBehavior:FBSDKLoginBehaviorWeb];
        [self.loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
        {
            if ([result.grantedPermissions containsObject:@"publish_actions"])
            {

            }}];
    }
}

So, the error is that I get the login page again and again request the user credentials when called getSharingPermissions. Please help. Thanks in advance.

+4
source share

Source: https://habr.com/ru/post/1584075/


All Articles