Using google-signin without metadata tags

醉酒当歌 提交于 2019-12-11 12:07:53

问题


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:

Missing required parameter 'client_id'

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

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

Why I don't want to use metadata tags

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.


回答1:


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

I imagine you have

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

and

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

What you should do is:

  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.

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

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.



来源:https://stackoverflow.com/questions/35983283/using-google-signin-without-metadata-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!