如何使用Facebook iOS SDK 4.x“重新申请”电子邮件权限? [英] How to “rerequest” email permission using Facebook iOS SDK 4.x?

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

问题描述

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

  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(@授予所有权限 );
if([FBSDKAccessToken currentAccessToken])
{
[[FBSDKGraphRequest alloc] initWithGraphPath:@me参数:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection * connection,id result,NSError * error )
{
if(!error)
{
NSLog(@%@,result);
}
}];
}
}
else
{
NSLog(@未授予);
}
}
}];

除非用户拒绝访问电子邮件,否则这很好用。我在FacebookSDK文档中看到,我可以重新请求访问用户的电子邮件一次。根据FB文档:如链接中给出的那样,

 如果有人拒绝了您的应用的权限,登录对话框将不会让您的应用重新请求权限,除非您通过auth_type = rerequest以及您的请求。 

启用重新验证


在您选择的登录流程中,我们向您展示了如何使用Login
对话框和OAuth来验证某人并从
请求权限。要重新认证,您可以使用额外的
参数来执行相同的步骤来强制执行:



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

  auth_nonce:包含可用于提供重放保护的生成的字母数字随机数的应用程序。查看如何查看auth_nonce 

更多。



以下是使用JavaScript SDK触发
重新身份验证的示例,使用重新验证的auth_type:



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



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



access_token = USER_ACCESS_TOKEN& expires = SECONDS_UNTIL_TOKEN_EXPIRES& auth_type = reauthenticate


< blockquote>

如何通过iOS SDK将auth_type = rerequest传递到Facebook的服务器?有没有一个特殊的方法?

解决方案

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



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



我需要通过 auth_type:'rerequest',同时再次请求,我得到这个方法的文档,我得到的描述:


在请求读取权限时使用此方法。您只应在需要
的权限时解释
用户的价值。如果拒绝权限,您可以检查result.declinedPermissions还向用户提供
的更多信息。



如果 [FBSDKAccessToken currentAccessToken] 不为零,将
视为该用户的重新授权,并将
rerequest标志传递到登录对话框。


只是问题是我正在调用注销 FbSDKLoginManager类的方法。这将清除令牌,它将把它作为旧许可不被重新请求的权限。


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?

解决方案

I resolved issue by recalling the method :

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

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

Use this method when asking for read permissions. You should only ask for permissions when they are needed and explain the value to the user. You can inspect the result.declinedPermissions to also provide more information to the user if they decline permissions.

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.

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“重新申请”电子邮件权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆