Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Created January 31, 2013 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloaj/4680055 to your computer and use it in GitHub Desktop.
Save juanpabloaj/4680055 to your computer and use it in GitHub Desktop.
AppsScript: get calendar events with same name.
function authorize() {
var oauthConfig = UrlFetchApp.addOAuthService("calendar");
var scope = "https://www.googleapis.com/auth/calendar";
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
}
function beginEnd(calId, eventName){
authorize();
var key = "...";
var query = encodeURIComponent(eventName);
calId = encodeURIComponent(calId);
var params = {
method: "get",
oAuthServiceName: "calendar",
oAuthUseToken: "always",
};
var url = "https://www.googleapis.com/calendar/v3/calendars/"+
calId+"/events?q=" + query + "&key=" + key;
var request = UrlFetchApp.fetch(url, params);
var response = Utilities.jsonParse(request.getContentText());
var items = response.items;
for ( i = 0 ; i < items.length ; i++){
var start = (items[i].start.dateTime);
var end = (items[i].end.dateTime);
Logger.log( [start,end]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment