Re: Calendar API Question
Hi Salesnav
I have not actually worked with the Google Calendar API, but have done a lot with the DriveApi. To be fair to Google, I think their docs make it pretty easy to do this kind of thing, but when I do it in my OAuth/REST courses I direct my students to the Google API Explorer (I'm deliberately [B]not[/B] including a link to that, because every time I need it - as in those courses - I just Google it! <g>). From there I just go to the API I want (the one I use in the course is the Drive API, but I'm a bit behind and the current version is v3, so I click the "All Versions" link on the left and pick the Drive v2 one I am familiar with). You would want the Calendar API. Then I think you want the calendar.events.insert method, so click on that, put in your gmail address (Note: I use [EMAIL="mjpeat@gmai.coml"]mjpeat@gmail.com[/EMAIL] day to day, but signed up as [EMAIL="mjpeat@googlemail.com"]mjpeat@googlemail.com[/EMAIL] originally, and that's the one it wants) , the start and end (Note: they are the wrong way round, logically, being lexically sorted: "e" before "s") dates (or dateTimes), maybe another property below, say description, then click the "Authorize and execute".
It will then show you the JSON request to send to do that and the response you will get back. Example (I just did this):
[CODE]
[B]Request[/B]
[COLOR=#000000][FONT=&] POST https://www.googleapis.com/calendar/v3/calendars/mjpeat%40gmail.com/events?key={YOUR_API_KEY} {
"end": {
"date": [COLOR=#008800]"2017-07-14"[/COLOR]
},
"start": {
"date": [COLOR=#008800]"2017-07-13"[/COLOR]
},
"description": [COLOR=#008800]"AcccuServ meeting at Unicorn"[/COLOR]
}
[/FONT][/COLOR]
[B]Response[/B]
[COLOR=#000000][FONT=&] 200 [COLOR=#500050][FONT=arial]- Show headers -[/FONT][/COLOR]
{
[COLOR=#444444][IMG]https://support.dataaccess.com/Forums/image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAAANUlEQVR42mNgGNqgHYj/Y8HTsClmBOIlaAo3AjEzLtPZgHgvVOEJIOYi5Bx IN4GxNKDNLgAp6IN47aYlEUAAAAASUVORK5CYII=[/IMG][/COLOR]
"kind": [COLOR=#008800]"calendar#event"[/COLOR],
"etag": [COLOR=#008800]"\"2999690546402000\""[/COLOR],
"id": [COLOR=#008800]"90v06b6vkmc1g51nfiirl2o454"[/COLOR],
"status": [COLOR=#008800]"confirmed"[/COLOR],
"htmlLink": "[URL]https://www.google.com/calendar/event?eid=OTB2MDZiNnZrbWMxZzUxbmZpaXJsMm80NTQgbWpwZWF0QG0[/URL]",
"created": [COLOR=#008800]"2017-07-12T07:41:13.000Z"[/COLOR],
"updated": [COLOR=#008800]"2017-07-12T07:41:13.253Z"[/COLOR],
"description": [COLOR=#008800]"AcccuServ meeting at Unicorn"[/COLOR],
"creator": {
"email": [COLOR=#008800]"mjpeat@gmail.com"[/COLOR],
"displayName": [COLOR=#008800]"Mike Peat"[/COLOR],
"self": [COLOR=#000088]true[/COLOR]
},
"organizer": {
"email": [COLOR=#008800]"mjpeat@gmail.com"[/COLOR],
"displayName": [COLOR=#008800]"Mike Peat"[/COLOR],
"self": [COLOR=#000088]true[/COLOR]
},
"start": {
"date": [COLOR=#008800]"2017-07-13"[/COLOR]
},
"end": {
"date": [COLOR=#008800]"2017-07-14"[/COLOR]
},
"iCalUID": [COLOR=#008800]"90v06b6vkmc1g51nfiirl2o454@google.com"[/COLOR],
"sequence": [COLOR=#000088]0[/COLOR],
"reminders": {
"useDefault": [COLOR=#000088]false[/COLOR],
"overrides": [
{
"method": [COLOR=#008800]"email"[/COLOR],
"minutes": [COLOR=#000088]10[/COLOR]
},
{
"method": [COLOR=#008800]"popup"[/COLOR],
"minutes": [COLOR=#000088]30[/COLOR]
}
]
}
}
[/FONT][/COLOR]
[/CODE]
Can I ask what version of DataFlex you are using? IMO v19.0 makes this much easier, because of the cJsonObjects it introduces (Thanks Harm! <g>).
Mike
Re: Calendar API Question
I found that created an untitled event in my calendar, so you might try (just a guess - I have not looked at any doc) adding "title": "WhateverYouWantToCallIt" just after the description in the JSON.
Mike
Re: Calendar API Question
Hi Mike, thanks for responding. I have successfully used that tool to create a calendar event but I'm not figuring out the translation part. Also, they give you the layout of the different event parameters but not the code for the most important ones like the calendar ID. I've been using your test bed, the google test. It's the operation field and the content field I'm having trouble with. First can I even use the operation and content fields? What would you enter there. For the operation I've been using calendar/v3/users/me/calendarList. The scope is [url]http://www.googleapis.com/auth/calendar[/url]. That works fine if you don't touch anything else, just execute. The question comes in how exactly do you feed the rest of the information to create the event in the calendar. I'm thinking you can't just use the operation and content fields and format something for them , it's not enough. I don't know your code well enough yet. I am thinking I need to tear into the packages today that you created to see what's in there. I'm not getting the way to do a JSON request quite yet. Like, is it a string, some other thing. I will work on it today. Any help is appreciated. Like.....
in google drive, after you make the connection using your testing tool, what code are you using to send the JSON request exactly. I'd be happy to post what works out here when I'm done. I would think there is a lot of us VDF programmers that could use to attach a calendar, a free one to our apps. BTW, I'm still on 18.2. I usually wait til a full release. Thanks again
Re: Calendar API Question
Salesnav
As I said, I have not done anything with the Google Calendar API, so I'm as much in the dark about that as you are. I wish I had more time to help, but I'm a bit snowed under ATM.
Sorry!
Mike
Re: Calendar API Question
Bummer. As usual, bumping down the hack at it Sam road again. Thanks Mike, you got it this far. I'll post what I find out when I find out.
Re: Calendar API Question
Hi Mike, been studying this all day. I have the token, I see the exact http: I have to send. I have to add parameters which is the JSON code in the header
POST https://www.googleapis.com/calendar/v3/calendars/{email@gmail.com}/events?key={tokenAPI_Key}
}
"end": {
"dateTime": "2017-07-13T09:45:00.0z"
},
"start": {
"dateTime": "2017-07-13T09:30:00.0z"
},
"summary": "Test Event"
}
The above works using the APIs Explorer for calendars.events.insert
These parameters need to be put into a struct. got that, understood
2 questions and I don't need for you to figure this out for me, just point me in the right direction
1. How do I add the convert the struct to JSON?
2. How do I add that to the Header?
Maybe this is a simple question but it's just not spelled out anywhere I can find
This is the url
POST https://www.googleapis.com/calendar/v3/calendars/{email@gmail.com}/events?key={tokenAPI_Key}
How do the parameters get added to that command line above in laymen's terms
Thanks
1 Attachment(s)
Re: Calendar API Question
Salesnav
First, the JSON needs to go in the HTTP Body, not the Header.
Second, getting data from your structs into JSON. Well here is why I think you should consider DataFlex v19.0. In it Harm has introduced JSON objects, which make this simple:
[CODE]
Struct tGoogleCalCreateEvent
DateTime end
DateTime start
String summary
End_Struct
Struct tGoogleCalCreateEventResponse
// I'm leaving this for you to do based on the response JSON from API Explorer (or use RestGen - attached)
End_Struct
Class cMyHttpTransfer is a cHttpTransfer
Procedure Construct_Object
Property UChar[] pucaData
Property String psContentType
End_Procedure
Procedure OnDataReceived string sContentType string sData
UChar[] ucaData
Get pucaData to ucaData
Move (AppendArray(ucaData, StringToUCharArray(sData))) to ucaData
Set pucaData to ucaData
Set psDataType to sContentType
End_Procedure
End_Class
Function SendMyJsonStuff tGoogleCalCreateEvent tData Returns tGoogleCalCreateEventResponse
Handle hoJson hoHttp hoResp
UChar[] ucaData ucaResp
Boolean bOK
Integer iStat
String sPath
tGoogleCalCreateEventResponse tResp
Get Create (RefClass(cJsonObject)) to hoReq
Send DataTypeToJson of hoJson tData
Get StringifyUTF8 of hoJson to ucaData
Send Destroy of hoJson
Get Create (RefClass(cMyHttpTransfer)) to hoHttp
Set psRemoteHost of hoHttp to "[COLOR=#000000]www.googleapis.com[/COLOR]"
Move "[COLOR=#000000]calendar/v3/calendars/{YOUR_GMAIL_ADDRESS}/events?key={YOUR_API_KEY}[/COLOR]" to sPath
Get HttpVerbAddrRequest of hoHttp sPath (AddressOf(ucaData)) (SizeOfArray(ucaData)) False "POST" to bOK
If iOK Begin
Get ResponseStatusCode of hoHttp to iStat
If ((iStat >= 200) and (iStat < 300)) Begin
Move (pucaData(hoHttp)) to ucaResp
Get Create (RefClass(cJsonObject)) to hoResp
Get ParseUtf8 of hoResp ucaResp to bOK
If bOK Begin
Get JsonToDataType of hoResp to tResp
End
Else Error 999 "JSON parse failed"
Send Destroy of hoResp
End
Else Error 999 ("HTTP status" * String(iStat))
End
Else Error 999 "HTTP request failed"
Send Destroy of hoHttp
Function_Return tResp
End_Function
[/CODE]
(Note: I wrote this directly into the post - it has [B][U]not[/U][/B] been tested!!!)
Writing the structs is difficult/tedious, but I have a little program which helps, generating them into package files from sample JSON: RestGen (attached).
If you want to do it in 18.2 it is harder, but RestGen will generate code to help you do it in those packages (absolutely no warranty though!).
Mike
Re: Calendar API Question
PS - when using RestGen, add it to your Studio Tools menu with the parameter <workspace> which will let it figure out where to put things.
Also, maybe look at my Microsoft Office365 API here: [URL]https://support.dataaccess.com/Forums/attachment.php?attachmentid=9278&d=1443028243[/URL]
Mike
Re: Calendar API Question
When I have this done, I will modify your GoogleTest.wo to include getting the calendar to work and send you all of it. Thank you very very much. It's exactly what I needed. You're a good man.