With the help of Mr Marco Cioffi, I finally added a Google Calendar event with VBScript. He posted a great example script (one that I’ve been searching for over the last several days), but his site is in “Maintenance Mode” so I had to access the cached version.
This example uses the “MSXML2.ServerXMLHTTP” object, which can retrieve data from remote servers as well as perform GET and POST methods. This transaction is done on the server, and is therefore invisible to the user (though it may be vulnerable to sniffing, I think)
Replace “me@gmail.com” with your email/calendar name, and “secret” with your password.
NOTE: Google strongly recommends NOT using the username/password login authentication in web apps. Use AuthSub instead.
Here’s my implementation:
<%
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", "https://www.google.com/accounts/ClientLogin", false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "accountType=HOSTED_OR_GOOGLE&Email=me@gmail.com&Passwd=secret" _
& "&source=Gulp-CalGulp-1.05&service=cl"
lines = Split(xmlhttp.responseText, vbLf)
nvp = Split(lines(2), "=")
set xmlhttp = nothing
calentry = "<?xml version='1.0' ?><entry xmlns='http://www.w3.org/2005/Atom' " _
& "xmlns:gd='http://schemas.google.com/g/2005'>" _
& "<category scheme='http://schemas.google.com/g/2005#kind' " _
& "term='http://schemas.google.com/g/2005#event'></category>" _
& "<title type='text'>Tennis with Beth</title>" _
& "<content type='text'>Meet for a quick lesson.</content>" _
& "<gd:transparency " _
& "value='http://schemas.google.com/g/2005#event.opaque'>" _
& "</gd:transparency>" _
& "<gd:eventStatus " _
& "value='http://schemas.google.com/g/2005#event.confirmed'>" _
& "</gd:eventStatus>" _
& "<gd:where valueString='Rolling Lawn Courts'></gd:where>" _
& "<gd:when startTime='2010-01-22T15:00:00.000Z' " _
& "endTime='2010-01-22T17:00:00.000Z'></gd:when>" _
& "</entry>"
url = "http://www.google.com/calendar/feeds/default/private/full"
postEntry(url)
function postEntry(url)
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", url, FALSE
xmlhttp.setRequestHeader "Content-type", "application/atom+xml"
xmlhttp.setRequestHeader "X-If-No-Redirect", "True"
xmlhttp.setRequestHeader "Authorization", "GoogleLogin auth=" & nvp(1)
xmlhttp.send calentry
testUrl = InStr(url,"?gsessionid")
if testUrl=0 then
redirect = xmlhttp.getResponseHeader("X-Redirect-Location")
postEntry(redirect)
end if
set xmlhttp = nothing
end function
%>
This will definitely come in handy later.
Hello,
Where can i get help using vbscript accesing google contacts api ?
Ingeman
August 17, 2010 @ 10:32 am
I’ve actually never used google contacts API. I’m sure that it’s similar, as the google API all works the same.
September 9, 2010 @ 5:53 pm
Did you extend this example at all? I used your example and made great strides but just cannot retrive and update a Calendar entry.
I have tried adapting the .NET examples but I am pulling my hair out!
Any pointers would be brilliant!
Kevin
May 22, 2011 @ 7:29 am