使用GIS(Google Identity Services)和API子包(Picker),而无需客户端包

发布于 2025-01-27 13:35:05 字数 1310 浏览 4 评论 0 原文

我目前正在根据 tokenclient 根据 tokenclient 来替换 gapi.oauth2 软件包。 Web/指南/迁移到GIS“ rel =“ noreferrer”>指南,一切正常。

global.google.accounts.oauth2
        .initTokenClient({
            client_id: CONFIG.google.clientId,
            scope: 'https://www.googleapis.com/auth/drive.readonly',
            ux_mode: 'popup',
            callback(tokenResponse) {
                if (tokenResponse && !tokenResponse.error) {
                    onSuccess(tokenResponse.access_token);

                    return;
                }

                onError(tokenResponse.error || 'google authentication failed');
            },
        })
        .requestAccessToken({});

唯一的问题是我们不使用 gapi.client ,并且宁愿避免加载该软件包,因为我们只使用令牌来通过使用 google.picker.picker.pickerbuilder 。 现在,在初始化之后,GSI软件包试图使用 gapi.client.settoken(),显然由于没有加载软件包而失败。

[gsi_logger-token_client]:设置令牌失败。 gapi.client.settoken undefined。

因此,现在我找不到有关如何防止发生这种情况的任何内容代码>作为占位符。

有谁知道是否有任何官方方法来处理?

I am currently replacing the gapi.oauth2 package, by using the TokenClient according to the guide and everything works fine.

global.google.accounts.oauth2
        .initTokenClient({
            client_id: CONFIG.google.clientId,
            scope: 'https://www.googleapis.com/auth/drive.readonly',
            ux_mode: 'popup',
            callback(tokenResponse) {
                if (tokenResponse && !tokenResponse.error) {
                    onSuccess(tokenResponse.access_token);

                    return;
                }

                onError(tokenResponse.error || 'google authentication failed');
            },
        })
        .requestAccessToken({});

The only issue is that we are not using the gapi.client and would prefer avoiding loading that package as we are only using the token to show a picker by using google.picker.PickerBuilder.
Now after the initialization the GSI package tries to use gapi.client.setToken() which obviously fails as the package is not loaded.

[GSI_LOGGER-TOKEN_CLIENT]: Set token failed. Gapi.client.setToken undefined.

So now i could not find anything in the reference on how to prevent that call to happen, nor how to at least suppress the warning by not e.g hacking in a noop as a placeholder.

Does anyone know if there is any official way to deal with that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流星番茄 2025-02-03 13:35:05

在我的测试中,访问令牌已成功返回到回调处理程序。

它看起来是一个错误生成的警告,令人讨厌的是,但是从功能上看,您还可以。后来的官方发布应删除警告,而无需采取任何措施。

In my tests the access token is successfully returned to the callback handler.

It looks to be an incorrectly generated warning, annoying yes, but functionally you're okay. A later, official release should remove the warning with no action on your part required.

夜清冷一曲。 2025-02-03 13:35:05

GIS的新API(Google Identity Services)可能会删除GAPI的销售。
我必须通过代码修复它。

gapi = {client: {setToken: function(){ return; }}}; 

The new API of GIS (Google Identity Services) maybe remove the setToken of the gapi.
I had to fix it by the code.

gapi = {client: {setToken: function(){ return; }}}; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文