我正在尝试编写一个角度应用来处理youtube数据api。我使用this angular wrapper获取了Google登录按钮。当我在oauth对话框中选择我的gmail帐户时,一切正常,但是当我选择我的品牌帐户时,尽管权限在https://myaccount.google.com/permissions显示为已授予,但我收到了消息{"error": "invalid_request"}
的403 / p>
组件打字稿:
import { Component } from '@angular/core';
import { GoogleSignInSuccess, GoogleSignInFailure } from 'angular-google-signin';
@Component({
selector: 'nav-menu',
templateUrl: './navmenu.component.html',
styleUrls: ['./navmenu.component.css']
})
export class NavMenuComponent {
private clientId: string = "copied from google dev console";
private scope: string = "https://www.googleapis.com/auth/youtube.force-ssl " +
"https://www.googleapis.com/auth/youtube.readonly";
private title: string = "Hello there!";
private theme: string = "default";
onGoogleSignInSuccess(event: GoogleSignInSuccess) {
let googleUser: gapi.auth2.GoogleUser = event.googleUser;
let id: string = googleUser.getId();
let profile: gapi.auth2.BasicProfile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
}
onFailure(event: GoogleSignInFailure) {
console.log(event);
}
}
html模板的相关部分:
<google-signin [clientId]="clientId"
[width]="240"
[height]="50"
[scope]="scope"
[longTitle]="true"
[theme]="theme"
(googleSignInSuccess)="onGoogleSignInSuccess($event)"
(googleSignInFailure)="onFailure($event)">
</google-signin>
查询发送到https://accounts.google.com/o/oauth2/iframerpc
的参数action=issueToken
response_type=token id_token
login_hint=snip
client_id=snip
origin=http://localhost:8001
scope=openid profile email
ss_domain=http://localhost:8001
我已将http://localhost:8001置于允许的来源中。我不知道范围参数是怎么回事。此请求由Google的javascript库提出。它工作时完全相同,响应表明我实际要求的范围