本文介绍了如何使用 Facebook iOS SDK 4.x“重新请求"电子邮件权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 FacebookSDK 4.x 与自定义 UI 集成,并使用以下方法登录并获得用户的电子邮件许可.

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");
            }
        }
    }];

除非用户拒绝访问电子邮件",否则这很有效.我在 FacebookSDK 文档中看到,我可以一次重新请求访问用户的电子邮件.根据 FB 文档:如本 link

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.

启用重新验证

在您选择的登录流程中,我们向您展示了如何使用登录对话和 OAuth 对某人进行身份验证并从中请求权限他们.要重新进行身份验证,您可以使用这些相同的步骤以及附加的强制参数:

auth_type:该参数指定请求的认证功能(以逗号分隔的列表).有效的选项是:https - 检查是否存在安全的 Facebook 会话,如果不存在则要求重新验证reauthenticate - 要求此人无条件地重新进行身份验证

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

了解更多.

这是一个使用 JavaScript SDK 触发的示例使用 auth_type 的 reauthenticate 进行重新验证:

Here is an example using the JavaScript SDK that triggers re-authentication using an auth_type of reauthenticate:

FB.login(function(response) {//原始FB.login代码}, { auth_type: 'reauthenticate' })

请注意,响应正文包含 auth_type 参数您指定,例如:

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

access_token=USER_ACCESS_TOKEN&expires=SECONDS_UNTIL_TOKEN_EXPIRES&auth_type=reauthenticate

如何通过 iOS SDK 将auth_type=rerequest"传递给 Facebook 的服务器?有什么特别的方法吗?

How do I pass "auth_type=rerequest" to Facebook's servers via the iOS SDK? Is there a special method for that?

推荐答案

我通过回忆方法解决了问题:

I resolved issue by recalling the method :

[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)

我需要在再次请求时传递 auth_type: 'rerequest' 并且我在此方法的文档中得到它我得到了描述:

I need to pass auth_type: 'rerequest' while requesting again and i get it in the documentation of this method i get the description :

请求读取权限时使用此方法.你应该只问在需要时获取权限并向用户.您可以检查 result.decliningPermissions 还提供如果用户拒绝权限,则向用户提供更多信息.

如果[FBSDKAccessToken currentAccessToken] 不为零,则为被视为对该用户的重新授权,并将通过登录对话框的重新请求"标志.

If [FBSDKAccessToken currentAccessToken] is not nil, it will be treated as a reauthorization for that user and will pass the "rerequest" flag to the login dialog.

问题是我正在调用 FbSDKLoginManager 类的 logout 方法.这将清除令牌,并将其作为旧权限而不是重新请求的权限.

just the problem was i was calling logout Method of FbSDKLoginManager class. This will clear the token and it will takes it as the old permission not re-requested permission.

这篇关于如何使用 Facebook iOS SDK 4.x“重新请求"电子邮件权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 05:23
查看更多