Google应用引擎授权返回null

Google应用引擎授权返回null

问题描述:

我有以下代码,我在另一个程序中成功使用了

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

index.html



吃新鲜





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()正在返回null到我的k如果我没有登录,我不知道如何刷新登录或强制登出。任何帮助将不胜感激。

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.

更改以下

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.