Я добавил http://localhost:4200
в Авторизованные источники JavaScript в Google Credentials.
Но я все еще получаю ту же ошибку, когда пытаюсь нажать Войти через Google.
Вот мой код:
Я добавил ниже js import в мой index.html
файл
<script src="https://apis.google.com/js/platform.js" async defer></script>
Код файла компонента:
declare const gapi: any;
clientId:string = '248871214048-
rkg3p17piu27bl2o58fftdoq43cepb37.apps.googleusercontent.com';
private scope = [
'profile',
'email',
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/contacts.readonly',
'https://www.googleapis.com/auth/admin.directory.user.readonly'
].join(' ');
public auth2: any;
public googleInit() {
gapi.load('auth2', () => {
this.auth2 = gapi.auth2.init({
client_id: this.clientId,
cookiepolicy: 'single_host_origin',
scope: this.scope
});
this.attachSignin(this.element.nativeElement.firstChild);
});
}
public attachSignin(element) {
this.auth2.attachClickHandler(element, {},
(googleUser) => {
let profile = googleUser.getBasicProfile();
console.log('Token || ' + googleUser.getAuthResponse().id_token);
console.log('ID: ' + profile.getId());
// ...
}, function (error) {
console.log(JSON.stringify(error, undefined, 2));
});
}
ngAfterViewInit() {
this.googleInit();
}