GoogleAuth javascript API未检测到已登录的用户
我使用的是GoogleJavaScriptAPI,它可以直接登录,尽管它无法检测到已经登录页面的用户。 这是我的密码:GoogleAuth javascript API未检测到已登录的用户,javascript,api,google-oauth,Javascript,Api,Google Oauth,我使用的是GoogleJavaScriptAPI,它可以直接登录,尽管它无法检测到已经登录页面的用户。 这是我的密码: loadGoogleAPI() { const script = document.createElement("script"); let $this = this; script.onload = () => { gapi.load('client:auth2', () => {
loadGoogleAPI() {
const script = document.createElement("script");
let $this = this;
script.onload = () => {
gapi.load('client:auth2', () => {
gapi.client.init({
apiKey: '',
clientId: '',
scope: 'https://www.googleapis.com/auth/classroom.courses profile',
accessType: 'offline'
}).then(() => {
let auth2 = gapi.auth2.getAuthInstance();
console.log(auth2);
auth2.currentUser.listen((val) => {
this.setState({auth2: this.state.auth2});
console.log(val)
});
if (auth2.isSignedIn.get()) {
console.log(1);
this.state.auth2.signIn();
}
auth2.attachClickHandler(Style.parse('sign-in-button'), {}, function(user) {
console.log(user);
}, function (err) {
console.log(err);
});
this.setState({auth2})
});
});
};
script.src = "https://apis.google.com/js/platform.js";
document.head.appendChild(script);
}
输出是什么?你把密码放在哪里?您如何知道登录名有效且未被检测到?它只是在初始加载时输出null,我知道登录名有效,因为登录名成功通过并返回正确的用户对象。我使用react,只是通过将单击处理程序附加到按钮来进行初始登录。代码在类中,这一切都是在开火——因此我能够登录并看到它在工作。