Facebook graph api 如何获取Firebase用户的名字
我有一个通过Firebase身份验证的用户。我可以得到他们的显示名称,但想知道如何得到他们的名字只。我是否必须使用某种令牌来调用FB Graph API 诚恳 维沙尔 是的,你需要获得一个令牌,它基本上允许你获取用户的Facebook详细信息 一旦您获得了一个经过验证的令牌,那么您就可以使用FB Graph API来提取基本信息 下面是一个示例代码Facebook graph api 如何获取Firebase用户的名字,facebook-graph-api,firebase,firebase-authentication,Facebook Graph Api,Firebase,Firebase Authentication,我有一个通过Firebase身份验证的用户。我可以得到他们的显示名称,但想知道如何得到他们的名字只。我是否必须使用某种令牌来调用FB Graph API 诚恳 维沙尔 是的,你需要获得一个令牌,它基本上允许你获取用户的Facebook详细信息 一旦您获得了一个经过验证的令牌,那么您就可以使用FB Graph API来提取基本信息 下面是一个示例代码 let credential = FIRFacebookAuthProvider.credential(withAccessToken: acces
let credential = FIRFacebookAuthProvider.credential(withAccessToken: accessToken.tokenString)
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if let error = error
{
print("Login error: \(error.localizedDescription)")
let alertController = UIAlertController(title: "Login Error", message: error.localizedDescription, preferredStyle: .alert)
let okayAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(okayAction)
self.present(alertController, animated: true, completion: nil)
return
}
if((FBSDKAccessToken.current()) != nil) {
var request = FBSDKGraphRequest(graphPath: "me", parameters:["fields":"first_name,last_name,email"], httpMethod: "GET")
request?.start(completionHandler: {(connection,result,error) -> Void in
if (error == nil)
{
var dictionary_user_info = result as? NSDictionary
let v_firstname = dictionary_user_info?.object(forKey: "first_name") as! String
let v_lastname = dictionary_user_info?.object(forKey: "last_name") as! String
let v_email = dictionary_user_info?.object(forKey: "email") as! String
}
}
}
是的,你需要获得一个令牌,它基本上允许你获取用户的Facebook详细信息
一旦您获得了一个经过验证的令牌,那么您就可以使用FB Graph API来提取基本信息
下面是一个示例代码
let credential = FIRFacebookAuthProvider.credential(withAccessToken: accessToken.tokenString)
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if let error = error
{
print("Login error: \(error.localizedDescription)")
let alertController = UIAlertController(title: "Login Error", message: error.localizedDescription, preferredStyle: .alert)
let okayAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(okayAction)
self.present(alertController, animated: true, completion: nil)
return
}
if((FBSDKAccessToken.current()) != nil) {
var request = FBSDKGraphRequest(graphPath: "me", parameters:["fields":"first_name,last_name,email"], httpMethod: "GET")
request?.start(completionHandler: {(connection,result,error) -> Void in
if (error == nil)
{
var dictionary_user_info = result as? NSDictionary
let v_firstname = dictionary_user_info?.object(forKey: "first_name") as! String
let v_lastname = dictionary_user_info?.object(forKey: "last_name") as! String
let v_email = dictionary_user_info?.object(forKey: "email") as! String
}
}
}