使用不带元数据标签的Google登录 [英] Using google-signin without metadata tags

查看:86
本文介绍了使用不带元数据标签的Google登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用不带元数据标签的google登录库. (最后的解释)

I am trying to use the google signin lib without the metadata tags. (explanation for this at the end)

我似乎在很大程度上可以正常工作,但是当页面加载时,我遇到了一个未捕获的异常:

I largely seem to have this working but when my page loads I get an uncaught exception:

缺少必需的参数"client_id"

Missing required parameter 'client_id'

尽管我未在元数据中指定客户端ID,但auth lib显然仍在尝试初始化.

The auth lib is obviously still trying to initialise despite me not specifying the client id in the metadata.

有什么办法可以关闭lib,以便它尝试初始化,直到我调用 gapi.auth2.init 函数?

Is there any way of turning the lib off so that it does attempt the initialise until I call the gapi.auth2.init function?

我从文档中获得了很好的例子但是我想将此lib合并到我的使用角度服务登录的角度应用程序中.我希望我的角度服务控制lib何时初始化,何时登录并处理结果.使用元数据标签的示例很棒,但是似乎可以自己做所有事情,而没有给我太多控制权. 例如,当lib正在初始化并登录时,我想要一个加载状态,在此初始状态得到解决之前,我不希望显示登录按钮.

I have the example from the docs working great but I want to incorporate this lib into my angular app that uses an angular service to sign in. I want my angular service to control when the lib is initialised, when it signs in and deal with the results. The example using metadata tags is great but seems to do everything itself without giving me much control. For example, I want a loading state as the lib is initialising and logging in, I do not want to show a login button until this initial state has been resolved.

推荐答案

使用声明性方法以及框架来加载Google登录按钮往往是一个问题.我建议您尝试命令式方法.

Loading Google Sign-In button using declarative approach along with a framework tend to be a problem. I recommend you to try imperative approach.

我想你有

<div class="g-signin2"></div>

<script src="https://apis.google.com/js/platform.js"></script>

您应该做的是:

  1. 删除.g-signin2并指定一个ID.因为该库会自动检测g-signin2并尝试将其替换为按钮小部件.
  2. 使用JavaScript,将函数绑定到调用手动登录的按钮.
  3. 在您感到舒适时(例如,在框架完全加载后)进行手动初始化.客户端ID可以作为auth2.init()参数的一部分包含.
  1. Remove .g-signin2 and specify an id. Because the library auto-detects the g-signin2 and tries to replace it with a button widget.
  2. Using JavaScript, bind a function to the button which invokes a manual sign-in.
  3. Do manual initialization when you feel comfortable (for example, after the framework is completely loaded). The client id can be included as part of auth2.init() params.

您可以在此处找到详细信息. https://developers.google.com/identity/sign-in/web /build-button

You can find details here. https://developers.google.com/identity/sign-in/web/build-button

FWIW,您可以使用https://apis.google.com/js/api.js代替platform.js. platform.js适用于要使用小部件的情况.

FWIW, you can use https://apis.google.com/js/api.js instead of platform.js. platform.js is for when you want to use widgets.

这篇关于使用不带元数据标签的Google登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆