Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gapi.client.init promise fails silently #680

Closed
insomniac807 opened this issue Oct 9, 2020 · 1 comment
Closed

gapi.client.init promise fails silently #680

insomniac807 opened this issue Oct 9, 2020 · 1 comment

Comments

@insomniac807
Copy link

Possible duplicate here.

importing gapi as object using this script

import {
    gapi
} from 'gapi-script';
import oauth2Keys from './oauthKeys.json';
const APIKEYS = oauth2Keys.web;
const DISCOVERY_DOCS = ['https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest'];
const SCOPES = ["https://www.googleapis.com/auth/youtube.readonly", "https://www.googleapis.com/auth/youtube"];

//im building a vuejs3 application
mounted() {
    gapi.load('client:auth2', this.initClient);
},
    data() {
        return {
            GOOGLEAUTH: null
        }
    },
    methods: {
        initClient() {
            var self = this;
            console.log("initialising client...");
            gapi.client.init({
                discoveryDocs: DISCOVERY_DOCS,
                clientId: APIKEYS.client_id,
                scope: SCOPES
            }).then(function () {
                console.log(self);
                //listen for sign-in state changes
                self.GOOGLEAUTH = gapi.auth2.getAuthInstance();

                console.log("googleauth is....");
                console.log(self.GOOGLEAUTH);

                self.GOOGLEAUTH.isSignedIn.listen(self.updateSigninStatus);
                // Handle initial sign-in state. (Determine if user is already signed in.)
                self.updateSigninStatus(self.GOOGLEAUTH.currentUser.get());
            });
        }
}

Console logs in the promise callbacks not running. this.GOOGLEAUTH returning undefined in subsequent code. If I remove the clientid and scope params, the console logs run but this.GOOGLEAUTH still returning undefined.

@dvanderb
Copy link
Collaborator

dvanderb commented Oct 9, 2020

Thanks for the issue report. We do not support using the linked module to load GAPI since it is a snapshot of the GAPI loading code which appears to be at least 8 months old at this point which results in loading old versions of the libraries. Please use officially documented methods of loading the libraries and try your use case again(samples: https://github.com/google/google-api-javascript-client/blob/master/docs/samples.md)

@dvanderb dvanderb closed this as completed Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants