Use Google Calendar API

Has anybody tried to use the Google Calendar API? Are there any libraries from Google for RealBasic/Xojo? Googled a little bit and found only this:
http://forums.realsoftware.com/viewtopic.php?f=1&t=30572

Okay, I read the whole stuff at Google about OAuth and ClientLogin and tried the above example - changed only the following line
me.SetRequestContent(ev.RawSource,"application/atom+xml")
to
me.SetRequestContent("Content-Type","application/atom+xml")

The login works perfect (status=200). Then I get always the status=302 response (Moved Temporarily) and it follows the new URL - but then I get “Content is not allowed in prolog.

Googled long time and it seems that there is data before the XML content. But I don’t have any XML content.
http://www.breathteching.com/2011/02/01/content-is-not-allowed-in-prolog-google-api/

Has somebody any idea or inputs?

Hello Urs,

I am also not able to sign into google. Here is an example program (which does not work) and I am working on the code to try and get a status = 200.

In this example change the email and password information in the pushbutton action event to your email and password.

GoogleSignIn

Urs, you have been able to get farther than I have, as I cannot get status = 200.

Does anyone have some simple working code for this?

Thanks for your help :slight_smile:

Did you read that whole article Urs? The author said that the problem was an extra space at the end of one of his headers and that he had to trim the value of each line.

The library isn’t complete but it can do most things for Calendar, Tasks, and Gmail. You might want break on exceptions off when testing.

https://www.dropbox.com/s/vj2e7mj3pxzkij8/GoogleAPIShareable.xojo_binary_project?dl=0

Thanks for the information Brock and Greg,

I will look into this some more. :slight_smile:

Hello Brock,

Thanks for the demonstration program. It looks like I am doing something wrong as I am getting an “Out of Bounds Exception Error” in the Window1 Open event with the code:

dim c as integer = response.messages(0).AttachmentCount

The following code was changed to the generated APIKey, ClientID, and ClientSecret. Refresh Token was left empty as one was not generated (not sure if this was a problem?).

Dim g as new GoogleAPI.Google g.ApiKey = "AIza...etc" g.ClientId = "etc.....googleusercontent.com" g.ClientSecret = "etc...H" g.TokenType = "Bearer" //Set USer g.refreshToken = ""

Do you have any other hints, tips, or tricks to get your original code working?

Thanks for your help :slight_smile:

Same here. Probably something basic we’re missing @Eugene Dakin

http://googleappsupdates.blogspot.be/2014/10/deprecated-google-calendar-apis-v1-v2.html

https://developers.google.com/google-apps/calendar/

[quote=162547:@Eugene Dakin]Hello Brock,

Thanks for the demonstration program. It looks like I am doing something wrong as I am getting an “Out of Bounds Exception Error” in the Window1 Open event with the code:

dim c as integer = response.messages(0).AttachmentCount

The following code was changed to the generated APIKey, ClientID, and ClientSecret. Refresh Token was left empty as one was not generated (not sure if this was a problem?).

Dim g as new GoogleAPI.Google g.ApiKey = "AIza...etc" g.ClientId = "etc.....googleusercontent.com" g.ClientSecret = "etc...H" g.TokenType = "Bearer" //Set USer g.refreshToken = ""

Do you have any other hints, tips, or tricks to get your original code working?

Thanks for your help :)[/quote]

Did you confirm that “response.messages(0)” exists?
If your query returned no results then this would throw an outOfBounds exception

The code in the Open event was just some sample code I was playing with for my own email so at the time I knew it existed. For my filters. You’ll also need to make sure that your AuthToken has permissions to all the API’s you want it to use.

I’m assuming you mean this:

dim response as GoogleAPI.ListMessagesResponse = g.User.Messages.List(false,"",10,"","",true) dim c as integer = response.messages(0).AttachmentCount

You will want to make your code safe, like this:

dim response as GoogleAPI.ListMessagesResponse = g.User.Messages.List(false,"",10,"","",true) if response.messages.Ubound > -1 then dim msg as GoogleAPI.Message = response.messages(0) dim attachmentCount as integer = msg.AttachmentCount if attachmentCount > 0 then dim a as GoogleAPI.MessageAttachment = msg.Attachment(0) end end

Basic coding stuff :slight_smile:
Let me know if you have any trouble after this, I’d be happy to help :slight_smile:

EDIT=====

I also just looked at my example and you do NEED to set the Refresh Token. You DONT NEED to set the (regular) Token. The refresh token allows a normal token to be generated whenever it needs a new one (they expire periodically).

[quote=162212:@Brock Nash]The library isn’t complete but it can do most things for Calendar, Tasks, and Gmail. You might want break on exceptions off when testing.

https://www.dropbox.com/s/vj2e7mj3pxzkij8/GoogleAPIShareable.xojo_binary_project?dl=0[/quote]

Would you also sell licenses of an unencrypted version of your Google classes?

Potentially. If I get around to finishing them O.o. I need to wrap the google docs API and a few other things first. And there’s a handful of missing methods here and there that I didn’t get around to implementing and testing because I wasn’t going to need them. I might offer them as some form of shareware - donateWare too.

Hi Brock,

Thanks for the suggestion. I changed some of the code to the following:

[code] Dim g as new GoogleAPI.Google
g.ApiKey = “AIzaSyB-GNSywzvdnADF-r4cd8vanPlF9RL0-HM”
g.ClientId = “845367174060-l5ora9kk7rap9ojuuqmf6r9a2h34p2is.apps.googleusercontent.com
g.ClientSecret = “fIlTkw5_2FHTNoSGEI1OOjAH”
g.TokenType = “Bearer”
//Set USer
g.refreshToken = “”

dim attachmentCount as integer
dim response as GoogleAPI.ListMessagesResponse = g.User.Messages.List(false,"",10,"","",true)
if response.messages.Ubound > -1 then
dim msg as GoogleAPI.Message = response.messages(0)
attachmentCount = msg.AttachmentCount
if attachmentCount > 0 then
dim a as GoogleAPI.MessageAttachment = msg.Attachment(0)
end
end
MsgBox "attachmentCount = " + CStr(attachmentCount)
[/code]

I still need to cleanup the file code yet, but this is a start. I am getting an attachment count of zero, and am guessing this is a 1 in a zero-based array - am I correct? I think it has connected?

I want to play and create some Google Drive API stuff. How did you use g.ApiKey, g.ClientId, g.ClientSecret , and g.TokenType to connect to the Google API so that I can roll-my-own?

Thanks for the code!

[quote=162634:@Eugene Dakin]I still need to cleanup the file code yet, but this is a start. I am getting an attachment count of zero, and am guessing this is a 1 in a zero-based array - am I correct? I think it has connected?

I want to play and create some Google Drive API stuff. How did you use g.ApiKey, g.ClientId, g.ClientSecret , and g.TokenType to connect to the Google API so that I can roll-my-own?

Thanks for the code![/quote]

Correct. The arrays a standard Xojo arrays so they are 0-based.
And remember you will need to your RefreshToken in your example in order for it to work.
@Dirk Cleenwerck linked to the GoogleApi Docs above. My library uses HTTPSecureSocket in order to talk to Google but there is a fair amount of work with serialization and class creation in order to get this library to work.

@Brock Nash Thanks for the classes! But I can’t find this ‘refreshToken’ you are talking about. Is it something fixed that we can choose ourselves or is it something the Google API returns?

You get the token through OAuth of someone’s user account.

.

That would be awesome! I would be willing to pay, like I do for MBS or BKeeney tools.

Or, before you let your work die somewhere in a dusty corner, then you could think of open sourcing it on github.

@broke nash any news about this?