iOS facebookSDK获取用户的完整详细信息 [英] iOS facebookSDK get user full details

查看:171
本文介绍了iOS facebookSDK获取用户的完整详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Iam使用最后一个FBSDK(使用swift)

Iam using the last FBSDK (using swift)

    //MARK: sign in with facebook
func signInWithFacebook()
{
    if (FBSDKAccessToken.currentAccessToken() != nil)
    {
        // User is already logged in, do work such as go to next view controller.
        println("already logged in ")
        self.returnUserData()

        return
    }
    var faceBookLoginManger = FBSDKLoginManager()
    faceBookLoginManger.logInWithReadPermissions(["public_profile", "email", "user_friends"], handler: { (result, error)-> Void in
        //result is FBSDKLoginManagerLoginResult
        if (error != nil)
        {
            println("error is \(error)")
        }
        if (result.isCancelled)
        {
            //handle cancelations
        }
        if result.grantedPermissions.contains("email")
        {
            self.returnUserData()
        }
    })
}

func returnUserData()
{
    let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

        if ((error) != nil)
        {
            // Process error
            println("Error: \(error)")
        }
        else
        {
            println("the access token is \(FBSDKAccessToken.currentAccessToken().tokenString)")

            var accessToken = FBSDKAccessToken.currentAccessToken().tokenString

            var userID = result.valueForKey("id") as! NSString
            var facebookProfileUrl = "http://graph.facebook.com/\(userID)/picture?type=large"



            println("fetched user: \(result)")


}



<当我打印获取的用户时,我只得到了id和名字! ,
但是我要求获得电子邮件和朋友和个人资料的许可,
出了什么问题?

when I print the fetched user I get only the id and the name ! , but i requested a permission for email and friends and profile , what's wrong ???

BTW:我从我的macbook中移动了这个项目到另一个macbook(因为我格式化了)它在我创建项目的macbook上工作得非常好,但在移动项目后(使用bitbucket clone)我得到了这个结果。

BTW : I moved this project from my macbook to another macbook ( because I formatted mine) it worked very well when it was at the the macbook which I created the project on , but after moving the project (using bitbucket clone) I got this results .

推荐答案

根据新的Facebook SDK,您必须使用 FBSDKGraphRequest

As per the new Facebook SDK, you must have to pass the parameters with the FBSDKGraphRequest

if((FBSDKAccessToken.currentAccessToken()) != nil){
    FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
        if (error == nil){
            println(result)
        }
    })
}

文件链接: https://developers.facebook.com/docs/facebook-login/permissions/v2.4

用户对象参考: https://developers.facebook.com/docs/graph-api/reference/user

使用公开个人资料,您可以获得性别:

With public profile you can get gender :

public_profile (Default)

Provides access to a subset of items that are part of a person's public profile. A person's public profile refers to the following properties on the user object by default:

id
name
first_name
last_name
age_range
link
gender
locale
timezone
updated_time
verified

这篇关于iOS facebookSDK获取用户的完整详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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