angular - 为什么 Google 登录在 Angular 应用程序的 Angular Web 应用程序中不起作用?
问题描述
我正在尝试让谷歌登录我的网络应用程序。我尝试按照本教程进行谷歌登录但即使谷歌登录按钮也没有显示。我想在http://localhost:4200/home进行身份验证,而不是在http://localhost:4200
这是我的主页 HTML 的样子
<html>
<head>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="998210766859-ag7cijtb0md9cj6oj9nvqis5kk8g7929.apps.googleusercontent.com">
</head>
<body>
<br>
<a href="#" onclick="signOut();">Sign out</a>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
</script>
</body>
</html>
这是对应的component.ts
import { Component, OnInit } from '@angular/core';
import { BlogService } from '../blog.service';
import { Blogpost } from '../blogpost';
@Component({
selector: 'app-frontpage',
templateUrl: './frontpage.component.html',
styleUrls: ['./frontpage.component.css']
})
export class FrontpageComponent implements OnInit {
public lis = [];
public l1 ="siba";
constructor(private servo:BlogService) { }
ngOnInit(): void {
this.servo.getblogs()
.subscribe(data => this.lis = data);
}
onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}
}
最后一部分是 onSignIn 函数。
但是当我运行该应用程序时,登录按钮没有出现,只需退出锚标记即可。
解决方案
在这里试试这个包 angularx-social-login ,它很容易实现。
推荐阅读
- jquery - jQuery html函数异步而不是同步
- python - 如何将 MJPEG 流写入文件的正确方法是什么
- flutter - Flutter 通过提供者访问推送页面上的通知程序
- r - 限制 ggplot2 轴的因子数
- list - 如何在 SwiftUI 列表中显示排序的递归数据结构?
- java - 如何在 Java 中检查字符串的多个条件?
- c# - 抽象类属性导致 JSON.NET 在反序列化期间抛出
- mysql - 无法连接到 docker 容器外的 mariadb
- scheme - SICP 练习 1.40 问题
- reactjs - URL changes but component is not render - React Router