嗨我已更新到
swift 3并且收到错误:
Value of type ‘Any?’ has no member ‘valueForKey’
对于以下代码行:
let userName : NSString? = result.valueForKey("name") as? NSString let facebookID : NSString? = result.valueForKey("id") as? NSString let firstName : NSString? = result.valueForKey("first_name") as? NSString let lastName : NSString? = result.valueForKey("last_name") as? NSString let email : NSString? = result.valueForKey("email") as? NSString
非常感谢!
编辑:
完整代码:
if((FBSDKAccessToken.current()) != nil){ FBSDKGraphRequest(graPHPath: "me",parameters: ["fields": "id,name,first_name,last_name,email"]).start(completionHandler: { (connection,result,error) -> Void in if (error == nil){ let userName : NSString? = result.valueForKey("name") as? NSString let facebookID : NSString? = result.valueForKey("id") as? NSString let firstName : NSString? = result.valueForKey("first_name") as? NSString let lastName : NSString? = result.valueForKey("last_name") as? NSString let email : NSString? = result.valueForKey("email") as? NSString
回答:
FBSDKGraphRequest(graPHPath: "me",error) -> Void in if (error == nil){ let data:[String:AnyObject] = result as! [String : AnyObject] let userName : NSString? = data["name"]! as? NSString let facebookID : NSString? = data["id"]! as? NSString let firstName : NSString? = data["first_name"]! as? NSString let lastName : NSString? = data["last_name"]! as? NSString let email : NSString? = data["email"]! as? NSString