android 403 for <script src="https://accounts.google.com/gsi/client" 异步延迟></script>

Tha*_*lip 9 javascript android android-studio ionic-framework angular

当在本地运行我的 Angular(离子框架)应用程序时,通过浏览器一切正常,但是当通过 android studio 运行或打包并推送到手机中时,我得到 403。

这是在index.html 的这一行: <script src="https://accounts.google.com/gsi/client" async defer></script>

我正在尝试按照此页面集成/实现“使用 Google 登录”按钮:https://developers.google.com/identity/gsi/web/guides/client-library

有什么指点吗?

提前致谢!

小智 1

我在 REACT 中遇到了同样的问题..

我的问题的解决方案是在 google.accounts.id 上方添加 /* global google */ 。

/* global google */ 通过将此行放在我们的代码上方,它将自动引用 index.html 文件内的脚本。

React.js 示例

import './App.css';
import { React, useEffect } from 'react'
import jwt_decode from 'jwt-decode'

function App() {

  function handleCallbackResponse(response) {
    var userObject = jwt_decode(response.credential);
    console.log(userObject);
  }
  useEffect(() => {

    /* global google */  <-- Add this line before calling google.accounts.id

    google.accounts.id.initialize({
     client_id: "Your Client ID here",
     callback: handleCallbackResponse
    })

    google.accounts.id.renderButton(
     document.getElementById("signInDiv"),
      { theme: "outline", size: "large" }
    );

    return () => {
    }
  }, [])


  return (
   <div className="App">
   <div id="signInDiv"></div>
   </div>
  );
}

export default App;
Run Code Online (Sandbox Code Playgroud)