【问题标题】:can i get user name from Facebook api? , I need user name to use [duplicate]我可以从 Facebook api 获取用户名吗? ,我需要用户名才能使用[重复]
【发布时间】:2018-08-16 09:23:10
【问题描述】:

您好,我只是使用此 api 获取用户详细信息,但我无法获取用户名,请帮助我

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:[NSDictionary dictionaryWithObject:@"id,first_name,last_name,gender,email,picture.type(large),groups" forKey:@"fields"]]
 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

     if (error==nil) {
     }else {

         NSLog(@"facebook erro : %@ ",error);
     }
 }];

【问题讨论】:

    标签: ios objective-c facebook


    【解决方案1】:

    您需要获得访问非公开数据的权限。

    Check the blog here, it mentions how to request permission for private data.

    这是来自上述博客的sn-p

    let loginManager = FBSDKLoginManager()
    let permissions = ["public_profile", "email","username"] //not sure username is to be used or user_name.
    let handler = loginManager.logInWithReadPermissions(permissions, fromViewController: self, handler: handler)
    

    在用户授予对其私人数据的访问权限之后。您将能够检索数据。

    【讨论】:

    • FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; login.loginBehavior = FBSDKLoginBehaviorWeb; [登录 logInWithReadPermissions:@[@"public_profile",@"email",@"user_likes",@"user_groups",@"username",@"user_managed_groups"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error ) { if ([result.declinedPermissions containsObject:@"publish_actions"]) { NSLog(@"declained permissions"); } 其他 { } }];
    • 如果我使用关于代码的问题是“无效范围:用户名”
    • 你得到用户ID了吗?
    • 不,我与 FBSDKAccessToken 一起使用。 if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" 参数:[NSDictionary dictionaryWithObject:@"id,first_name,last_name,gender,email,picture.type(large),groups" forKey:@ "fields"]] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (error==nil) { }else { NSLog(@"facebook erro : %@ ",error); } }]; }
    【解决方案2】:

    Facebook iOS sdk 在 swift 3 中获取用户名和电子邮件 -

    FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
            if (error == nil){
                let fbDetails = result as! NSDictionary
                print(fbDetails)
            }else{
                print(error?.localizedDescription ?? "Not found")
            }
        })
    

    【讨论】:

    • 您需要获得访问私人用户数据的权限。上面的 sn-p 没有提到用户名。问题是检索用户名。
    • 是的,我需要那个谢谢@MukulMore
    猜你喜欢
    • 2011-08-12
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多