【发布时间】:2021-11-20 08:19:54
【问题描述】:
我正在尝试使用 gapi auth2 注册 google。以下代码位于 google-sigin.service.ts 中,我在其中定义了登录和注销功能。我在 this.subject.next(null) 中得到错误,错误是:
“null”类型的参数不能分配给“GoogleUser |”类型的参数未定义'。
export class GoogleSiginService {
private auth2!: gapi.auth2.GoogleAuth
private subject = new ReplaySubject<gapi.auth2.GoogleUser>(1)
constructor() {
gapi.load('auth2',()=> {
this.auth2 = gapi.auth2.init(
{
client_id:'184******'
}
)
})
}
public sigin(){
this.auth2.signIn({
scope:'https://www.googleapis.com/auth/gmail.readonly'
}).then(user => {
this.subject.next(user)
}).catch( ()=> {
this.subject.next(null)
})
}
public signOut()
{ this.auth2.signOut().then(()=>
{
this.subject.next(null)
})
}
public observable(): Observable<gapi.auth2.GoogleUser>
{
return this.subject.asObservable()
}
}
【问题讨论】:
标签: angular oauth-2.0 google-api-js-client