Google API get refrest token: Uncaught ReferenceError: offline is not defined

Google API get refrest token: Uncaught ReferenceError: offline is not defined

我正在尝试在用户使用 google 授权后获取刷新令牌。 这样用户就不必再次授权。 我研究了 Google 的文档,并且我知道我必须将访问类型置于离线状态。

现在,我尝试使用以下 javascript 代码:

 var cid = 'XXXXX';
 var apik = 'XXXX';
 var scopes = 'https://www.google.com/m8/feeds';


function authorizeWithGoogle() {
    gapi.client.setApiKey(apik); 
    gapi.auth.authorize({ client_id: cid, scope: scopes, immediate: false,     accesstype: offline }, handleAuthResult);}

function handleAuthResult(authResult) {
    if (authResult && !authResult.error) {
        console.log(JSON.stringify(authResult));
        $.get("https://www.google.com/m8/feeds/contacts/default/full?alt=json&access_token=" + authResult.access_token + "&max-results=11700&v=3.0",
        handleGoogleContacts);
    }
}

HTML 代码为:

 <input type="submit" class="btn btn-info" value="Google" onclick="authorizeWithGoogle()"/>

 <script src="https://apis.google.com/js/client.js"></script>

它给我以下错误:

Uncaught ReferenceError: offline is not defined

有人可以帮助我吗?谢谢

accesstype: offline <-- 正在离线查找变量,而不是字符串。用引号引起来。

accesstype: "offline"

下一个问题是您正在使用提交按钮,但您没有取消表单提交,因此页面将要提交。

onclick="authorizeWithGoogle(); return false"

有更好的方法来取消它,但这对内联事件很有效。