I am currently working on obtaining a refresh token once a user authorizes with Google in order to prevent the need for re-authorization. After studying Google's documentation, I learned that setting the access type to offline is necessary.
Now, I am experimenting with the following JavaScript code:
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);
}
}
Here is the HTML Code :
<input type="submit" class="btn btn-info" value="Google" onclick="authorizeWithGoogle()"/>
<script src="https://apis.google.com/js/client.js"></script>
An error message is being displayed:
Uncaught ReferenceError: offline is not defined
If anyone can provide assistance, it would be greatly appreciated. Thank you!