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 #15

Open
insomniac807 opened this issue Oct 9, 2020 · 0 comments
Open

gapi.client.init promise fails silently #15

insomniac807 opened this issue Oct 9, 2020 · 0 comments

Comments

@insomniac807
Copy link

This might be a bug with gapi itself rather than this script but I'll drop this here anyway. Possible duplicate here.

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.

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

1 participant