google-services.json如何取代default_web_client_id?

时间:2016-08-08 09:36:40

标签: java android android-studio google-play

首先,我想说我有谷歌播放登录和工作。但是,我一直在努力了解特定代码行的工作原理。

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();

我想知道requestIdToken是如何获得我真正的clientId的 调查时:default_web_client_id = 0x7f060035

当我记录R.string.default_web_client_id时,我得到: 2131099701

当我记录getString(R.string.default_web_client_id)时,我得到: xxxxxxx-xxxxxxxxx0tfctc0fa0a.apps.googleusercontent.com(我的网络客户端ID)

此ID不在我的字符串或资源文件夹中。但它在我的google-services.json文件中。

我的问题是getString或default_web_client_id如何解析为Json文件中的clientID?

提前感谢你的启蒙!

2 个答案:

答案 0 :(得分:5)

根据this,您应用gradle插件,然后使用JSON中的值生成新的xml文件

答案 1 :(得分:0)

首次将Firebase与项目集成后关闭项目。 DEFAULT_WEB_CLIENT_ID可能已从项目中删除。

因此,您必须手动添加default_web_client_id。

转到

res->字符串->值

并添加这样的字符串

private func swipeFunc() { let swipeGesture = UIPanGestureRecognizer(target: self, action: #selector(acknowledgeSwiped(sender:))) sliderImage.addGestureRecognizer(swipeGesture) swipeGesture.delegate = self as? UIGestureRecognizerDelegate } @objc func acknowledgeSwiped(sender: UIPanGestureRecognizer) { if let sliderView = sender.view { let translation = sender.translation(in: self.baseView) //self.sliderView switch sender.state { case .began: startingFrame = sliderImage.frame viewCenter = baseView.center fallthrough case .changed: if let startFrame = startingFrame { var movex = translation.x if movex < -startFrame.origin.x { movex = -startFrame.origin.x print("SWIPPERD minmax") } let xMax = self.baseView.frame.width - startFrame.origin.x - startFrame.width - 15 //self.sliderView if movex > xMax { movex = xMax print("SWIPPERD movex") } var movey = translation.y if movey < -startFrame.origin.y { movey = -startFrame.origin.y } let yMax = self.baseView.frame.height - startFrame.origin.y - startFrame.height //self.sliderView if movey > yMax { movey = yMax // print("SWIPPERD min") } sliderView.transform = CGAffineTransform(translationX: movex, y: movey) } default: // .ended and others: UIView.animate(withDuration: 0.1, animations: { sliderView.transform = CGAffineTransform.identity }) } } } override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { return sliderImage.frame.contains(point) }

You can also watch this video for more detail