Created
January 31, 2013 04:09
-
-
Save juanpabloaj/4680055 to your computer and use it in GitHub Desktop.
AppsScript: get calendar events with same name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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