ios FBSDKLoginManager logInWithReadPermissions?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29363270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 05:25:50  来源:igfitidea点击:

FBSDKLoginManager logInWithReadPermissions?

iosobjective-cfacebookfacebook-ios-sdkfacebook-sdk-4.0

提问by Omarj

I'm using FBSDKLoginButtonto allow to user login using Facebookand using FBSDKLoginButton.readPermissions = @[@"public_profile",@"email",@"user_likes",@"email",@"user_birthday"];

我正在使用FBSDKLoginButton允许用户登录使用Facebook和使用 FBSDKLoginButton.readPermissions = @[@"public_profile",@"email",@"user_likes",@"email",@"user_birthday"];

to ask for permissions , but I need one more permission which is publish_actions I should use FBSDKLoginManager

请求权限,但我还需要一个权限,即我应该使用的publish_actions FBSDKLoginManager

with

 logInWithReadPermissions:@[@"public_profile",@"user_likes",@"user_birthday"] 
logInWithPublishPermissions:@[@"publish_actions"]

but this for some reason affect on my permission "some of my permission are missing check image

但这出于某种原因影响了我的许可“我的某些许可缺少检查图像

Code:-

代码:-

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
                [login logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
                    if (error) {
                        // Process error
                    } else if (result.isCancelled) {
                        // Handle cancellations
                    } else {
                        // If you ask for multiple permissions at once, you
                        // should check if specific permissions missing
                        if ([result.grantedPermissions containsObject:@"publish_actions"]) {
                            // Do work
                        }
                    }
                }];

[login logInWithReadPermissions:@[@"public_profile",@"",@"user_likes",@"user_birthday"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    if (error) {
        // Process error
    } else if (result.isCancelled) {
        // Handle cancellations
    } else {
        // If you ask for multiple permissions at once, you
        // should check if specific permissions missing
        if ([result.grantedPermissions containsObject:@"email"]) {
            // Do work
        }
    }
}];

Result:-

结果:-

**it take long time to redirect the user to the permission view ? and not all my permission appear to user **

**将用户重定向到权限视图需要很长时间?并不是我的所有权限都显示给用户 **

enter image description here

在此处输入图片说明

Note:- I know that warning mean that i need to submit my app to review but this not what i'm asking about right now .

注意:- 我知道警告意味着我需要提交我的应用程序进行审核,但这不是我现在要问的。

Update

更新

When I Tried "Dheeraj Singh" solution but in this case user will be re-direct twice to the Facebook first time to get publish_action then to get email and birthday permission which is bad.

当我尝试“Dheeraj Singh”解决方案时,但在这种情况下,用户将被两次重定向到 Facebook 第一次以获取 publish_action 然后获取电子邮件和生日许可,这很糟糕。

回答by Dheeraj Singh

Facebook Login provides your app access to a person's public profile, friend list, and email address. These three permissions do not require review. Instead, your app's users will choose whether they want to grant access to this information.

Facebook 登录可让您的应用访问某个人的公开个人资料、好友列表和电子邮件地址。这三个权限不需要审核。相反,您的应用程序的用户将选择他们是否要授予对这些信息的访问权限。

In order for your app to access additional elements of a person's Facebook profile (read permissions) or to publish content to Facebook on their behalf (write permissions), you will need to submit for review.

为了让您的应用访问某人 Facebook 个人资料的其他元素(读取权限)或代表他们向 Facebook 发布内容(写入权限),您需要提交以供审核。

Refer to : https://developers.facebook.com/docs/apps/review#submitlogin

请参阅:https: //developers.facebook.com/docs/apps/review#submitlogin

Updated :

更新 :

Apps should separate the request of read and publish permissions.

应用程序应将读取和发布权限的请求分开。

 FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];

    [login logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // Process error
        } else if (result.isCancelled) {
            // Handle cancellations
        } else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if ([result.grantedPermissions containsObject:@"publish_actions"]) {
                // Do work

                [login logInWithReadPermissions:@[@"user_likes",@"user_birthday"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
                    if (error) {
                        // Process error
                    } else if (result.isCancelled) {
                        // Handle cancellations
                    } else {
                        // If you ask for multiple permissions at once, you
                        // should check if specific permissions missing
                        if ([result.grantedPermissions containsObject:@"user_birthday"]) {
                            // Do work

                            NSLog(@"Permission  2: %@",result.grantedPermissions);
                        }
                    }
                }];

            }
        }
    }];

You don't need public_profile in read permission as if granted permission to publish_actions it also gets permission for public_profile.

你不需要 public_profile 的读取权限,就像被授予了对 publish_actions 的权限一样,它也获得了 public_profile 的权限。

回答by V.J.

As i seen you code that you are trying to use the "user_likes", "user_birthday", "public_profile" and "publish_actions" permissions.

正如我看到您编写的代码,您正在尝试使用“ user_likes”、“ user_birthday”、“ public_profile”和“ publish_actions”权限。

From 1st May 2015 facebook has only enabled "public_profile", "email" and "user_friends" are available without the approval process.

从 2015 年 5 月 1 日起,facebook 只启用了“ public_profile”,“email”和“ user_friends”无需批准程序即可使用。

For "user_likes", "user_birthday" and "publish_actions" you need to get approval from the facebook.

对于“ user_likes”、“ user_birthday”和“ publish_actions”,您需要获得facebook 的批准。

For review process you can get help from Facebook Review.

对于审核流程,您可以从Facebook Review获得帮助。

回答by Waris Shams

I also have the same issue with user_posts permission for two weeks, but after some search i found the solution for this, if you still having this issue follow these steps

我也有两周的 user_posts 权限问题,但经过一番搜索,我找到了解决方案,如果您仍然遇到此问题,请按照以下步骤操作

  1. Go to http://developers.facebook.comand logged in to your developer account.
  2. Select your app and go to Roles section.
  3. Add a tester in Testers section.
  4. Then re-install the app and login using that tester account.
  5. Now you try to get the required permissions from tester and tester will see all the permissions list.
  1. 转到http://developers.facebook.com并登录到您的开发者帐户。
  2. 选择您的应用程序并转到角色部分。
  3. 在测试人员部分添加测试人员。
  4. 然后重新安装应用程序并使用该测试人员帐户登录。
  5. 现在您尝试从测试人员那里获取所需的权限,测试人员将看到所有权限列表。

回答by Ewerson

var login = FBSDKLoginManager()


@IBAction func fbBtnPressed(_ sender: AnyObject) {

    login.logIn(withReadPermissions: ["email"], from: self) { (FBSDKLoginManagerLoginResult, Error) in

        if Error != nil {
            print("O Login via Facebook Falhou. Erro: \(Error)")
        } else {
            let accessToken = FBSDKAccessToken.current().tokenString
            self.gotoScreen() //Function for screen after login succesfull 
            print("Acesso concedido ao Facebook. \(accessToken)")
        }

    }

}