无法阅读酒店的频道'未定义的youtube api

时间:2017-04-19 13:36:00

标签: angular typescript youtube youtube-api

无法使用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未定义

0 个答案:

没有答案