无法使用youtube api获取用户频道,也不知道出了什么问题。这是我的代码:
ngAfterViewInit(): void {
gapi.load('client', this.initGoogleAuthentication.bind(this));
}
initGoogleAuthentication() {
this.socialService.getConfiguration().subscribe(this.onConfigurationLoaded.bind(this));
}
onConfigurationLoaded(operation: OperationDataResult<Config>) {
if (operation && operation.success) {
const config = operation.model;
gapi.client.setApiKey(config.youtubeSecret);
gapi.auth.init(this.checkAuth());
} else {
console.log('failed loaded configuration ', operation);
}
}
checkAuth() {
gapi.auth.authorize({
client_id: this.oAuthKey,
scope: this.scopeLink, // https://www.googleapis.com/auth/youtube
immediate: true
},
this.handlaOAuthReslult.bind(this));
}
handlaOAuthReslult(authResult) {
if (authResult && !authResult.error) {
gapi.client.load('youtube',
'v3',
() => {
var request = gapi.client.youtube.channels.list({
mine: true,
part: 'id'
});
request.execute(response => {
let playlistId = response.result.items[0].contentDetails.relatedPlaylists.uploads;
});
});
} else {
gapi.auth.authorize({
client_id: this.oAuthKey,
scope: this.scopeLink,
immediate: false
}, this.handlaOAuthReslult.bind(this));
}
}
它属于handlaOAuthReslult函数,其中有两个错误,其中gapi.client.load
执行错误:
Request URL:https://content.googleapis.com/discovery/v1/apis/youtube/v3/rest?fields=kind%2Cname%2Cversion%2CrootUrl%2CservicePath%2Cresources%2Cparameters%2Cmethods%2CbatchPath%2Cid&pp=0&key=mykey
Request Method:GET
Status Code:400
执行gapi.client.youtube.channels.list
时出现和第二个错误,表示channels
未定义