我只是将facebookm集成到我的应用程序中。但每次FBSDKAccessToken.currentAccessToken()都发现没有,所以我无法获取用户数据。这是我的代码
override func viewDidLoad() {
if (FBSDKAccessToken.currentAccessToken() != nil)
{
print("Not loggedin...")
}
else
{
print("logged in...")
}
loginbutton.delegate = self
loginbutton.readPermissions = ["public_profile", "email", "user_friends"]
FBSDKProfile.enableUpdatesOnAccessTokenChange(true)
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
{
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, email, first_name, last_name"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
let email = result.valueForKey("email") as? String
let fbid = result.valueForKey("id") as! String
let fname = result.valueForKey("first_name") as! String
let lname = result.valueForKey("last_name") as! String
print(email)
}
})
}
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
print("User Logged Out")
}
或在appdelegate
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
{
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
所以这是我的代码,但每次我得到的结果都没有价值,当我的结果显示它没有可用的变量。所以哪里出错了