I am integrating FacebookSDK 4.x integration with custom UI and using following method to log-in and also getting email permission from user.
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error){
NSLog(@"%@",[error localizedDescription]);
}
else if (result.isCancelled){
NSLog(@"Cancled");
}
else
{
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"Granted all permission");
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
NSLog(@"%@",result);
}
}];
}
}
else
{
NSLog(@"Not granted");
}
}
}];
This works great unless the user denies access to "email". I see in the FacebookSDK docs that I can re-request access to the user's email one time. According to the FB docs: as given in this link
If someone has declined a permission for your app, the login dialog won't let your app re-request the permission unless you pass auth_type=rerequest along with your request.
Enabling Re-authentication
During your chosen login flow we showed you how to use the Login Dialog and OAuth to authenticate someone and request permissions from them. To re-authenticate, you can use these same steps with additional parameters to force it:
auth_type: this parameter specifies the requested authentication features (as a comma-separated list). Valid options are: https - checks for the presence of a secure Facebook session and asks for re-authentication if it is not present reauthenticate - asks the person to re-authenticate unconditionally
auth_nonce: includes an app generated alphanumeric nonce which can be used to provide replay protection. See how to check an auth_nonce
for more.
Here is an example using the JavaScript SDK that triggers re-authentication using an auth_type of reauthenticate:
FB.login(function(response) { // Original FB.login code }, { auth_type: 'reauthenticate' })
Note that the body of the response contains the auth_type parameter you specified, for example:
access_token=USER_ACCESS_TOKEN&expires=SECONDS_UNTIL_TOKEN_EXPIRES&auth_type=reauthenticate
How do I pass "auth_type=rerequest" to Facebook's servers via the iOS SDK? Is there a special method for that?