M
M
mechanicnikodimich2016-04-12 14:32:22
Google
mechanicnikodimich, 2016-04-12 14:32:22

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
}

Here is the action when the button is clicked:
@IBAction func googleSignInClicked(sender: UIButton) {
        var googleSignIn: GIDSignIn!
        googleSignIn = GIDSignIn.sharedInstance();
        googleSignIn.shouldFetchBasicProfile = true;
        GIDSignIn.sharedInstance().signInSilently()
        googleSignIn.signIn() }

And here is the actual function that handles singIn
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)")
        }
    }

When the button is clicked and GIDSignIn.sharedInstance().signInSilently() is triggered, we get the following error:
The operation couldn't be completed. (com.google.GIDSignIn error -4.)
It's just that GIDSignIn.sharedInstance().signIn takes us to the login and password entry page, and that's where her whole life ends.
In AppDelegate I have this flounder:
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
    }

Ultimately, I need to get a G+ user token to register it on the server, but so far I'm getting only shisha.
Tell me where to look?
PS Function logs disappeared
override class func canInitWithRequest(request: NSURLRequest) -> Bool {
  print("Request #\(requestCount++): URL = \(request.URL!.absoluteString) ")
}

No one has come across anything like this after dancing with g +?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question