首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于<script src=“src=异步></src=>的Android403

用于<script src=“src=异步></src=>的Android403
EN

Stack Overflow用户
提问于 2022-02-02 11:09:13
回答 1查看 1.1K关注 0票数 7

当在本地运行我的角度(离子框架)应用程序时,通过浏览器运行都很好,但是当通过android运行或打包并插入移动电话时,我会得到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

有什么指示吗?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2022-08-09 07:56:45

我在反应中遇到了同样的问题。

解决我的问题的方法是在google.accounts.id之上添加google.accounts.id全球google */。

/*全局google */通过将这一行置于我们的代码之上,它将自动引用index.html文件中的脚本。

React.js实例

代码语言:javascript
复制
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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70954547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档