javascript - android 403 for <script src ="https://accounts.google.com/gsi/client"async defer></script>

标签 javascript android angular android-studio ionic-framework

当通过浏览器在本地运行我的 Angular ( ionic 框架)应用程序时,一切正常,但是当通过 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
任何指针?
提前致谢!

最佳答案

我在 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;

关于javascript - android 403 for &lt;script src ="https://accounts.google.com/gsi/client"async defer>&lt;/script&gt;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70954547/

相关文章:

javascript - 无法使用 Javascript 将 HTML 按钮元素的标题或值设置为 C 度符号

android - Retrofit 2 如何从嵌套的 json 对象获取响应 (android)

java - 将逗号分隔的列表粘贴到 EditText 中并存储在 SQLite TABLE 的多行中

Angular Material 2 md-card 响应列

javascript - Jquery 无法读取 Contenteditable div,变量返回未定义

javascript - Primefaces 4.0 尝试调用错误的 tabChange 事件处理程序(TabView 内的 AccordionPanel)

css - Angular 7 - ngx-spinner 覆盖整个页面

angular - 运行 ng e2e 时 dist/out-tsc-e2e 在哪里?

javascript - 将谷歌地图标记颜色更改为我选择的颜色

android - 如何将文件下载到我的下载文件夹android