相关疑难解决方法(0)

Google Identity Service Oauth2 检测同意弹出窗口是否关闭

我正在使用 Google 身份服务,并面临一些问题。看一下下面的函数loginUser并得到access_token

const client = (window as any).google.accounts.oauth2.initTokenClient({
  client_id: process.env.GOOGLE_CLIENT_ID,
  scope: `profile email`,
  callback: '' // defined at request time
});

const loginUser = async () => {
  const tokenResponse = await new Promise<TokenResponse>((resolve, reject) => {
    try {
      // Settle this promise in the response callback for requestAccessToken()
      client.callback = (resp) => {
        if (resp.error !== undefined) {
          reject(resp);
        }
        resolve(resp);
      };
      // requesting access token
      client.requestAccessToken({ prompt: 'consent' });
    } catch (err) { …
Run Code Online (Sandbox Code Playgroud)

javascript google-oauth google-signin google-identity react-google-login

7
推荐指数
2
解决办法
3220
查看次数

Google Oauth 弹出取消回调

使用 Google 身份服务 (GSI) 时,我可以显示一个弹出窗口,要求用户连接他们的 Google 帐户。这是有很好的文档记录的,并且它与以下代码配合得很好:

const client = window.google.accounts.oauth2.initCodeClient({
  client_id: 'CLIENT_ID',
  scope: 'SCOPE',
  ux_mode: 'popup',
  callback: async (response) => {
    console.log('Response Google', response);
  },
});
client.requestCode();
Run Code Online (Sandbox Code Playgroud)

但是,如果用户关闭弹出窗口,我希望执行一些操作。我在在线文档和示例中找不到任何内容。我尝试了intermediate_iframe_close_callbacknative_callback,但关闭弹出窗口时都没有被调用。

那么,有可能吗?我该怎么做 ?

谢谢

javascript oauth-2.0 google-oauth google-api-js-client

6
推荐指数
1
解决办法
1349
查看次数

React-google-login 无法在我的隐身浏览器上运行

我尝试在我的项目中添加使用谷歌登录功能。我的代码如下:

<GoogleLogin
            clientId="my clientId"
            buttonText="Sign in with Google"
            onSuccess={handleSuccess}
            onFailure={handleFailure}
            cookiePolicy={'single_host_origin'}
            className="btn-google"
        />
Run Code Online (Sandbox Code Playgroud)

它适用于一般浏览器,但不适用于隐身浏览器。在隐身模式下,输入我的谷歌帐户的所有凭据后,我收到以下错误。

{error: "popup_closed_by_user"}
Run Code Online (Sandbox Code Playgroud)

frontend oauth npm reactjs

5
推荐指数
1
解决办法
2735
查看次数

尝试通过 Google Drive API 创建权限时出现“需要权限类型字段”错误

我从此处找到的 Node.js 的 Google Drive API Quickstart 中改编了代码,以尝试为 Google Drive 中的现有文件创建新权限。

无论我在代码中做了什么更改,我总是得到相同的响应,The permission type field is required即使我已经通过resourcenpmgoogleapis 客户端库的文档和我找到的其他示例中提到的方式指定了它。

这只是不起作用还是我错过了一些明显的东西?

更新权限的代码

function updateFilePermissions(auth) {

  var drive = google.drive({
    version: 'v3',
    auth: auth
  });

  var resourceContents = {
    role: 'writer',
    type: 'user',
    emailAddress: 'user@example.com'
  };

  drive.permissions.create({

    resource: resourceContents,
    fileId: aValidFileId,
    sendNotificationEmail: false,
    fields: 'id',

  }, function(err, res) {

    if (err) {

      // Handle error...
      console.error(err);

    } else {

      console.log('Permission ID: ', res.id);

    }

  }); …
Run Code Online (Sandbox Code Playgroud)

node.js google-drive-api

2
推荐指数
1
解决办法
1586
查看次数