简体   繁体   中英

Facebook SDK 4.x Permission issue iOS

I am trying to get Feed for logged in user's timeline. I have a login button, to which I am passing read permissions including user_posts . Amazingly, Facebook does not grant me this permission and ignores it.

Code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends", @"user_posts"];

    self.loginButton.delegate = self;

    if([FBSDKAccessToken currentAccessToken])
    {
        NSLog(@"Have access token");
        NSLog(@"permissions .... %@",[FBSDKAccessToken currentAccessToken].permissions);
        [self retrieveFeed];
    }

}

#pragma mark - Login Delegate

-(void) loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error
{
    NSLog(@"Login Successfully!!");
    NSLog(@"permissions .... %@",[FBSDKAccessToken currentAccessToken].permissions);

    [self retrieveFeed];

}

-(void) loginButtonDidLogOut:(FBSDKLoginButton *)loginButton
{

}

#pragma mark - Receive FB Feed

-(void) retrieveFeed
{       
    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/feed" parameters:nil];

    FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
    [connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

        NSLog(@"%@",result);

        if(error)
            NSLog(@"Some error FEED;;;;;; %@",error.localizedDescription);
    }];
    [connection start];
}

On Clicking login Button, I get following permissions screen. Facebook has ignored user_posts permission.

在此输入图像描述

Even if I try to get this permission later after login, Facebook tells me that I have already authorized app to do so , even when there is no such permission granted! The code for getting new permission is:

-(void) checkForFeedPermission
{
    if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"user_posts"]) {

        NSLog(@"already granted feed access");
          [self retrieveFeed];

    } else {
        FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
        [loginManager logInWithReadPermissions:@[@"user_posts"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {

            NSLog(@"requesting feed access");
             [self retrieveFeed];

        }];
    }
}

I have been banging my head on this issue for three days. Please suggest me where can I be wrong? Thanks.

I think that not working for grant user_posts as par Facebook developer documentation for permission you have to submit your Facebook app for review see i attach screenshot that clearly said.

在此输入图像描述

So you have to submit your facebook app for login review might be then you can able to set this permission at loginTime

If you are in development mode and not yet ready to publish the app for facebook review then the best way to do what you want is to use Test Users. In your facebook app dashboard go to Roles and create some test users. Note that its a separate tab and not Testers in the first tab. When you create test users you can by default assign what permissions should be assigned to that user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM