我试图获得更新令牌一旦用户授权与谷歌。这样用户就不用再授权了。我从Google那里学习了文档,我知道我必须让access类型离线。
现在,我尝试使用以下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>它给了我以下错误:
未定义的ReferenceError:未定义脱机
有人能帮我吗?谢谢
发布于 2015-04-22 18:39:00
accesstype: offline <--这是在寻找脱机变量,而不是字符串。用引号包起来。
accesstype: "offline"
下一个问题是,您使用的是提交按钮,但您没有取消表单提交,所以页面将提交。
onclick="authorizeWithGoogle(); return false"有更好的方法来取消它,但这将很好地与内联事件。
https://stackoverflow.com/questions/29805975
复制相似问题