Answer the question
In order to leave comments, you need to log in
Can't get a token when logging in with google plus?
Good afternoon everyone.
The situation is as follows:
Yes @IBOutlet weak var googleButton: UIButton!
When you click on this button, the user goes to the authorization page on google and at this moment everything works fine.
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().clientID = "866444479638-sknrnea2aiuv6npjlcf6o3l4231k44hq.apps.googleusercontent.com"
GIDSignIn.sharedInstance().shouldFetchBasicProfile = true
GIDSignIn.sharedInstance().scopes = ["profile", "email"]
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
}
@IBAction func googleSignInClicked(sender: UIButton) {
var googleSignIn: GIDSignIn!
googleSignIn = GIDSignIn.sharedInstance();
googleSignIn.shouldFetchBasicProfile = true;
GIDSignIn.sharedInstance().signInSilently()
googleSignIn.signIn() }
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
if (error == nil) {
print(user.userID )
print(user.authentication.idToken)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let MainView = storyboard.instantiateViewControllerWithIdentifier("SuccedView")
self.presentViewController(MainView, animated: true, completion: nil)
} else {
print("\(error.localizedDescription)")
}
}
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
}
override class func canInitWithRequest(request: NSURLRequest) -> Bool {
print("Request #\(requestCount++): URL = \(request.URL!.absoluteString) ")
}
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