reactjs - 无法读取未定义的属性“currentUser”。googleUser 值是否与 Google oauth2 中的 currentUser 相同?
问题描述
googleUser
价值和currentUser
谷歌一样吗auth2
?
componentDidMount() {
window.gapi.load("client:auth2", () => {
window.gapi.client
.init({
clientId:
'CLIENT-ID.apps.googleusercontent.com',
scope: "email"
})
.then(() => {
this.auth2 = window.gapi.auth2.getAuthInstance()
console.log('Current User Details :' , this.auth2.currentUser.Ab);
console.log(this.auth2);
});
console.log(this.auth2.currentUser);
});
}
解决方案
一个 GoogleUser 对象代表一个用户帐户。GoogleUser 对象通常通过调用 GoogleAuth.currentUser.get() 获得。
GoogleAuth.currentUser.get() 返回代表当前用户的 GoogleUser 对象。请注意,在新初始化的 GoogleAuth 实例中,当前用户尚未设置。使用 currentUser.listen() 方法或 GoogleAuth.then() 获取初始化的 GoogleAuth 实例。
https://developers.google.com/api-client-library/javascript/reference/referencedocs
推荐阅读
- python - Numpy 在保持形状的同时展平子阵列
- flutter - 如何在 Flutter 中优化 listview.builder
- java - 海绵我的世界服务器获取预留频道失败
- amazon-web-services - 在部署时将 SQS 注册为 lambda 触发器
- python - LinkedIn Scraping 返回仅包含列标题和空行的空数据框
- c# - 使用列表序列化对象比序列化列表花费更长的时间
- javascript - 隐藏div而不点击离开
- json - 使用 jq 将参数名称添加到 json 文件
- python - Python函数到文本文件中的多个单独的行
- android - 如何更新单个列表磁贴的状态(刷新)?