Skip to content

gapi.client.init call never returns #258

@Nilesh-P

Description

@Nilesh-P

I am trying to use the auth client in chrome extension.
I added content_security_policy in manifest.json
"content_security_policy": "script-src 'self' https://apis.google.com/; object-src 'self'"

Now it shows no errors in console.
console.log('1'); is executed.
But console.log('2'); in the example below is never executed.
Can you please help ?

Please note my source code below

<script type="text/javascript" src="https://apis.google.com/js/api.js"></script> <script type="text/javascript" src="js/google_login.js" ></script>

And js/google_login.js contents below:

var apiKey = 'AIzaSyCJX8auossfAykk1-UxTsJuDDq79plNAOA';

// Enter the API Discovery Docs that describes the APIs you want to
// access. In this example, we are accessing the People API, so we load
// Discovery Doc found here: https://developers.google.com/people/api/rest/
var discoveryDocs = ["https://people.googleapis.com/$discovery/rest?version=v1"];

// Enter a client ID for a web application from the Google API Console:
// https://console.developers.google.com/apis/credentials?project=_
// In your API Console project, add a JavaScript origin that corresponds
// to the domain where you will be running the script.
var clientId = '302294786959-tjqfcbdlr1cf8s23sdfuuonhmvcqe36s.apps.googleusercontent.com';

// Enter one or more authorization scopes. Refer to the documentation for
// the API or https://developers.google.com/people/v1/how-tos/authorizing
// for details.
var scopes = 'email profile';

function initClient() {
console.log('1');
gapi.client.init({
apiKey: apiKey,
discoveryDocs: discoveryDocs,
clientId: clientId,
scope: scopes
}).then(function(opt_onFulfilled, opt_onRejected) {
console.log('2');
// Handle the initial sign-in state.
var isSignedIn = gapi.auth2.getAuthInstance().isSignedIn.get();

    handleAuthClick();

});

}

function handleAuthClick(event) {
console.log('3');
gapi.auth2.getAuthInstance().signIn();
}

// Load the API and make an API call. Display the results on the screen.
function makeApiCall() {
gapi.client.people.people.get({
resourceName: 'people/me'
}).then(function(resp) {

    console.log(resp.result.names[0].givenName);
});

}
gapi.load('client:auth2', initClient);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions