Page 1 of 2

Google Calendar API

Posted: Thu Sep 25, 2008 10:17 pm
by gwthompson
Hi,

I have just upgraded to Revolution Enterprise 3.0 and am trying to implement the basic Google login API via the post command but am not having much luck.

Here is the code that is not working:

Code: Select all

on mouseUp
    set the sslCertificates to "/usr/share/curl/curl-ca-bundle.crt" 
    put  URLEncode("Email=myNmme@gmail.com&Passwd=myPassword&source=gwt-lagb-1&service=cl&accountType=HOSTED_OR_GOOGLE")  into myPost
    post myPost to URL "https://www.google.com/accounts/ClientLogin"
    put the result into field "myResult"
end mouseUp
I get error 403 Forbidden (BadAuthentication error) returned from Google.

However if I use cURL in a bit of sample code I found in the forums everything seems to work fine. One of the reasons I upgraded was to take avantage of the SSL capabilities without having to use cURL.

I really want to use Revolution as opposed to Adobe AIR to develop some internal "mashups" but a lot of them require SSL.

Any and all help would be greatly appreciated.

Thanks,
Gary

Posted: Thu Sep 25, 2008 11:16 pm
by Mark
Hi Gary,

Are you sure that Google accepts urls of that form (application/x-www-form-urlencoded)?

I'm not sure that the entire url should be urlEncoded. Try

Email=urlEncode(myNmme@gmail.com)&Passwd=urlEncode(myPassword)&source=gwt-lagb-1&service=cl&accountType=HOSTED_OR_GOOGLE")

Best,

Mark

Posted: Thu Sep 25, 2008 11:42 pm
by gwthompson
Hi Mark,

I gave your idea a try but got the same result.

Is there something different regarding the post command when used with https?

Thanks,
Gary

Posted: Fri Sep 26, 2008 1:04 am
by Mark Smith
I just tried this, and succeeded:

Code: Select all

on mouseUp
   set the sslcertificates to "/usr/share/curl/curl-ca-bundle.crt" 
   put "Email=myEmail.net&Passwd=myPassword&source=gwt-lagb-1&service=cl&accountType=HOSTED_OR_GOOGLE" into tPost
   put "https://www.google.com/accounts/ClientLogin" into tUrl
   post tPost to url tUrl
   put the result & cr & it
end mouseUp
No urlencoding, which is weird, since the docs say:
Data you send should be encoded using the URLEncode function.
Does that work for you?

Posted: Fri Sep 26, 2008 1:34 am
by gwthompson
I copied your entire code replacing only my email and password and am still getting the same result which makes me think there is something else going on. I can using the login manually at Google's site so I know it's not that.

This is really strange.

Are you using Revolution Enterprise 3.0?

Thanks for all of your help.

Gary

Posted: Fri Sep 26, 2008 3:35 pm
by trevordevore
Gary,

For readability I like to use libURLFormData(). I tried the following in Rev 3.0 gm-3 with my Google account info and it worked:

Code: Select all

libUrlSetSSLVerification false
put "https://www.google.com/accounts/ClientLogin" into theURL
put libUrlFormData("accountType", "GOOGLE", \
       "Email", theEmail, \
       "Passwd", thePassword, \
       "service", "xapi", \
       "source", "Blue Mango Learning Systems-ScreenSteps-2.1") into theData

post theData to theURL
put it
I recieved a 200 response header back (I used libURLSetLogField to watch the request/response headers) and 'it' contained the SID, LSID and Auth values.

So it appears that it should work assuming the username/password is correct.

Posted: Fri Sep 26, 2008 3:51 pm
by gwthompson
Hi Trevor,

That worked perfectly! However in my thirst to understand Revolution much better than I do now can you explain why this method works and my attempt using post to URl does not?

Also where is libUrlSetSSLVerification documented?

I obviously have a long way to go to really understand the power of Revolution!

Thanks for everyone's help!

Gary

Posted: Fri Sep 26, 2008 4:04 pm
by trevordevore
Actually I just left the 'URL' out by mistake. I just add it into my test and the code still works (post theData to URL theURL).

I didn't realize that libUrlSetSSLVerification isn't documented but it basically doesn't use certificates to verify that the server on the other end is really the server it is supposed to be. Fine for testing but it can be a security risk.

I just tried the following code and it worked as well:

Code: Select all

on mouseUp pMouseBtnNo
    libUrlSetSSLVerification true
    set the sslcertificates to "/usr/share/curl/curl-ca-bundle.crt"
    put "https://www.google.com/accounts/ClientLogin" into theURL
    put libUrlFormData("accountType", "GOOGLE", \
            "Email", theEmail, \
            "Passwd", thePassword, \
            "service", "xapi", \
            "source", "Blue Mango Learning Systems-ScreenSteps-2.1") into theData
    post theData to URL theURL
    put the result & cr & it
end mouseUp
Give it a try and let me know if it works for you as well.

Posted: Fri Sep 26, 2008 4:12 pm
by gwthompson
It still works for me as well.

I assume this is fake data in your example!

:)

Thanks for your help!

Gary

Posted: Fri Sep 26, 2008 4:26 pm
by gwthompson
Hi Trevor,

All of the sudden I am getting BadAuthorization errors returned from Google even though nothing has changed which leads me to believe there is something within Google's system that may be causing for whatever reason.

Would you have any idea about Google's limits especially if you have bad attempts?

Thanks for your help.

Gary

Posted: Fri Sep 26, 2008 5:44 pm
by gwthompson
I've done some more digging and the problem seems to be within Revolution. I added additional code and the first time through everything works fine. But any other tries produces the BadAuthorization error. If I quit Revolution and then restart the script again runs fine the first time.

Here is the script in question:

Code: Select all

on mouseUp
   libUrlSetSSLVerification false
   
   set the sslcertificates to "/usr/share/curl/curl-ca-bundle.crt" 
   
   put "myName@gmail.com" into theEmail
   put "myPassword" into thePassword
    
put "https://www.google.com/accounts/ClientLogin" into theURL
put libUrlFormData("accountType", "HOSTED_OR_GOOGLE", \
       "Email", theEmail, \
       "Passwd", thePassword, \
       "service", "cl", \
       "source", "gwt-lagb-1") into theData

post theData to theURL
put  it into field "output" 

 --read the AUTH string 
  set the itemdelimiter to "=" 
  put the last item of field "Output" into AUTH 

  put "http://www.google.com/calendar/feeds/default/owncalendars/full" into curlURL 
  put "Content-type: application/atom+xml" &LF &"Authorization: GoogleLogin auth=" &AUTH into field "HEADER" 
  set the httpheaders to field "HEADER" 
  get URL curlURL 
  put it into field "Output" 

  --Google sends a SSID cookie that has to be included if the first attempt fails 
  if field "Output" contains "Moved Temporarily" then 
    put offset("gsessionid=",field "Output") into fcharSSID 
    put offset(">here<",field "Output")- 2 into lcharSSID 
    put char (fcharSSID) to (lcharSSID) of field "Output" into SSID 
    post field "newevent" to curlURL &"?" &SSID 
    put it into field "Output" 
  end if 
end mouseUp
Is there something I should be "unloading" after each call?

Thanks for everyone's help!

Gary

Posted: Fri Sep 26, 2008 6:02 pm
by gwthompson
I have just discovered the problem. I didn't realize that when I set the httpHeaders further down in my script with additional custom information that data hangs around after the script has finished running. So subsequent calls to the same script would already have the httpHeaders set which was wrong for Google's Client Login requirements. By setting the httpHeaders to empty after making any custom calls eliminates the problem.

I guess I didn't realize that the httpHeaders was a "global" if you will.

Sigh.

So much to learn!

Thanks for everyone's help. I really appreciate the timely responses.

Gary

Posted: Fri Sep 26, 2008 6:19 pm
by trevordevore
Glad you got it working Gary.

Re: Google Calendar API

Posted: Sun Jan 17, 2010 3:49 pm
by trevix
I found this old post and I wonder if there is any further info on RunRev/Google calendar connections. Would be nice some example stack...

What I need is the ability to connect, download to a text file all the G calendars and be able to upload a new text file with the replacement of all the calendars on Google Cal.
Is this feasible ?

Re: Google Calendar API

Posted: Mon Jan 18, 2010 2:15 pm
by trevix
One more thing...
Do I need RunRev enterprise, to connect to Google calendar ? Vannot be done from Studio ?

Thanks