Question

I have the following code, which I am using successfully in another program

index.html Eat Fresh

</html>

init.js

function init() {
    CLIENT_ID = "927885761089.apps.googleusercontent.com"
    SCOPES = ["https://www.googleapis.com/auth/userinfo.email"]
    gapi.client.load('oauth2', 'v2', signin)
}

function signin() {
    gapi.auth.authorize({client_id: CLIENT_ID, scope: SCOPES, immediate: true}, userAuthed)
}

function userAuthed() {
    console.log(gapi.auth.getToken())
    console.log(gapi.auth.getToken().accessToken)
    gapi.client.oauth2.userinfo.get().execute(function(resp) {
    checkEmail(resp)
    })
}

function checkEmail(user) {
    var validEmail = (whiteList.indexOf(user.email) !== -1)
    if (!user.code && validEmail) {
        startApp()
    } else {
        displayError(user.email)
    }
}

gapi.auth.getToken() is returning null and to my knowledge that means that my I am not logged in. I don't know how to refresh the login or force a log out. Any help would be appreciated.

Était-ce utile?

La solution

Changing the the following

gapi.auth.authorize({client_id: CLIENT_ID, scope: SCOPES, immediate: false}, userAuthed)

will prompt the user to give permission to the app, thus allowing for an authorized access token and for the remainder of the code to work.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top