After User Offline Authorization, can I create events in the User's Calendar when the User is offline?

273 views
Skip to first unread message

David

unread,
Jun 13, 2013, 8:51:32 PM6/13/13
to google-api-jav...@googlegroups.com
The following tests are using my Goggle Calendar.

Using the JS API I can get an Auth. Code using the following code.

function handleAuthClick(event) {

var config = {
'client_id': clientId,
'access_type':'offline',
'approval_prompt': 'force',
'response_type':'code',
};

gapi.auth.authorize(config, function() {
var code = gapi.auth.getToken().code;            
console.log (code);           
});
}

This pops up a Request Permissions dialog requesting permission for the following:

Manage your Calendars
Perform these operations when I'm not using the application

But if I were to log out of my Calendar and attempt to insert an event, I get an error saying Login Required.

Can I insert events to my Calendar when I'm not logged into my Calendar using the JS API?

Thanks,

David


Jaffar Hussain

unread,
Jun 17, 2013, 12:55:47 AM6/17/13
to google-api-jav...@googlegroups.com
you cant do this if you are using JS API, you should be logged in.

David

unread,
Jun 18, 2013, 11:16:36 AM6/18/13
to google-api-jav...@googlegroups.com
Thanks Jaffar... that's too bad... offline access would be really nice.  Apart from the Javascript API, is there any way to insert an event into a google calendar offline?  I wouldn't mind using HTTP requests or jQuery Ajax calls but I keep running into Cross domain problems.  

Jaffar Hussain

unread,
Jun 19, 2013, 1:18:51 AM6/19/13
to google-api-jav...@googlegroups.com
Ya this is really bad.
In javascript i dont know if there is any way to do this but in PHP you can do this.
using google-api-php-client once a user has authorized then you can make any request to calendar if user is offline but you have to store accessToken.
In this case you will not run into cross domain problems aslo.

David

unread,
Jun 19, 2013, 9:40:58 AM6/19/13
to google-api-jav...@googlegroups.com
I'm not running a PHP server so that's not an option for me.

After reading a ton of material I understand the 3 Legged Authorization process using OAuth2.  

1.  Get an Authorization Code
2.  Trade the Authorization Code in for an Access Token and a Refresh Token.  The Access Token is good for an hour.
3.  When the Access Token expires, using the Refresh Token to get a new Access Token.  It's the Refresh Token that must be stored for later use in order to get new Access Tokens.

There must be a way to do this with Javascript, jQuery, Ajax, CORS and have offline access.

As you point out PHP, JAVA and other API libraries get it done.  So... what are they doing with the request that solves the cross domain problem?
Reply all
Reply to author
Forward
0 new messages