Answer the question
In order to leave comments, you need to log in
Doesn't get to see the client's token when logging in via facebook?
Good day, gentlemen.
There was a problem of the following nature:
I want to add a custom button to get a Facebook user token.
Here is the AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
NSURLProtocol.registerClass(TrainStarURLProtocol)
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
var flag: Bool = false
// handle Facebook url scheme
if let wasHandled:Bool = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
{
flag = wasHandled }
if let googlePlusFlag: Bool = GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication!, annotation: annotation) {
flag = googlePlusFlag
}
return flag
}
@IBOutlet weak var facebookbutton: UIButton!
class LoginViewController: UIViewController,GIDSignInUIDelegate,GIDSignInDelegate {
override func viewDidLoad() {
facebookbutton.addTarget(self, action: #selector(LoginViewController.loginFacebookAction(_:)), forControlEvents: UIControlEvents.TouchUpInside)
super.viewDidLoad()
}
func loginFacebookAction(sender: FBSDKLoginButton!) {
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
self.getFBUserData()
fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self) { (result, error) -> Void in
self.getFBUserData()
print("Done")}
}
func getFBUserData(){
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, email, access_token"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
//everything works print the user data
// let json = try! NSJSONSerialization.JSONObjectWithData (result! as! NSData, options: .MutableContainers) as! NSDictionary
let token = FBSDKAccessToken.currentAccessToken()
print(token)
}
else {
print(error.description)
}
})
}
}
}
FBSDKAccessToken.currentAccessToken()) == nil
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question