有谁知道为什么我会收到此错误?我有一个字段参数集。我对 swift 和编码很陌生,任何帮助将不胜感激。
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, gender"])
// start the request:
graphRequest.startWithCompletionHandler({
// void in means that it will return nothing upon completion
(connection, result, error) -> Void in
// do an error check
if error != nil {
print(error)
} else if let result = result {
PFUser.currentUser()?["gender"] = result["gender"]
PFUser.currentUser()?["name"] = result["name"]
PFUser.currentUser()?.save()
// use the user's FB id to get their public profile. First make their id a string:
let userId = result["id"] as! String
// next go to the internet and get their photo from FB:
let facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "/picture?type=large"
最佳答案
有一种方法可以让您获得对象“me”,然后您可以获取该对象的每个值
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if (error) != nil {
NSLog("Error: \(error)")
ActivityIndicatorWithLabel.shared.hideProgressView()
view.makeToast(message: "We are unable to connect to Facebook. Please try after sometime")
}else{
self.facebookData(result)
}
})
在此结果中,我们获得了用户的所有详细信息 这是一种从中获取的方法
func facebookData(result: AnyObject){
NSLog("Sending Login from facebook call")
var missingFields:[String] = []
userSocialDetailsGlobal.loginType = "facebook"
userSocialDetailsGlobal.socialId = result.valueForKey("id") as! String
userSocialDetailsGlobal.firstName = result.valueForKey("first_name") as! String
userSocialDetailsGlobal.lastName = result.valueForKey("last_name") as! String
userSocialDetailsGlobal.socialToken = FBSDKAccessToken.currentAccessToken().tokenString
}
struct userSocialDetailsGlobal {
static var socialId: String = String()
static var firstName: String = String()
static var lastName: String = String()
static var loginType: String = String()
static var socialToken: String = String()
}
关于ios - FBSDKLog : starting with Graph API v2. 4、对/me/permissions的GET请求应包含显式的 "fields"参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32539670/