Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Calendar API Question

  1. #1
    Join Date
    Feb 2009
    Location
    Temple, Texas
    Posts
    300

    Default Calendar API Question

    I am trying to figure out the correct format to create a calendar event. Once I get one thing working, I'll get the rest of it. I have

    "https://www.googleapis.com/auth/calendar as the scope. The login appears, it gets authorized and I get a token. You documentation and examples made that fairly easy. Thank you Mike Peat for that.

    The operation calendarList returns just fine although I noticed the L needs to be capitalized and the c lower case.
    The content is the part that gets me. The docs say you must provide 3 pieces of information but not how to format them.

    You need the calendarId: or Id:, the start: and stop: times as a minimum. The Id is your gmail email address or just primary.
    It says here https://developers.google.com/google...darList/insert how to use the insert command and the format referred to as the "body" The body is using a typical PHP type format. Just exactly what should be typed into the content area and the operation to get it to create a calendar event? Has anyone done this yet? Thanks ahead of time.

  2. #2
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default 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 not 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 mjpeat@gmail.com day to day, but signed up as mjpeat@googlemail.com 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:
    Request
    
     POST https://www.googleapis.com/calendar/v3/calendars/mjpeat%40gmail.com/events?key={YOUR_API_KEY} {
     "end": {
      "date": "2017-07-14"
     },
    
     "start": {
      "date": "2017-07-13"
     },
    
     "description": "AcccuServ meeting at Unicorn"
    
    }
     
    Response
    
     200 - Show headers -
      {
    
     "kind": "calendar#event",
     "etag": "\"2999690546402000\"",
     "id": "90v06b6vkmc1g51nfiirl2o454",
     "status": "confirmed",
     "htmlLink": "https://www.google.com/calendar/even...TQgbWpwZWF0QG0",
     "created": "2017-07-12T07:41:13.000Z",
     "updated": "2017-07-12T07:41:13.253Z",
     "description": "AcccuServ meeting at Unicorn",
     "creator": {
      "email": "mjpeat@gmail.com",
      "displayName": "Mike Peat",
      "self": true
    
     },
    
     "organizer": {
      "email": "mjpeat@gmail.com",
      "displayName": "Mike Peat",
      "self": true
    
     },
    
     "start": {
      "date": "2017-07-13"
     },
    
     "end": {
      "date": "2017-07-14"
     },
    
     "iCalUID": "90v06b6vkmc1g51nfiirl2o454@google.com",
     "sequence": 0,
     "reminders": {
      "useDefault": false,
      "overrides": [
       {
        "method": "email",
        "minutes": 10
    
       },
    
       {
        "method": "popup",
        "minutes": 30
    
       }
    
    
      ]
    
    
     }
    
    
    }
    
    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
    Last edited by Mike Peat; 12-Jul-2017 at 03:48 AM. Reason: Typo

  3. #3
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default 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

  4. #4
    Join Date
    Feb 2009
    Location
    Temple, Texas
    Posts
    300

    Default 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 http://www.googleapis.com/auth/calendar. 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

  5. #5
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default 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

  6. #6
    Join Date
    Feb 2009
    Location
    Temple, Texas
    Posts
    300

    Default 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.

  7. #7
    Join Date
    Feb 2009
    Location
    Temple, Texas
    Posts
    300

    Default 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

  8. #8
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default 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 "www.googleapis.com"
        Move "calendar/v3/calendars/{YOUR_GMAIL_ADDRESS}/events?key={YOUR_API_KEY}" 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
    (Note: I wrote this directly into the post - it has not 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
    Attached Files Attached Files

  9. #9
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default 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: https://support.dataaccess.com/Forum...8&d=1443028243

    Mike

  10. #10
    Join Date
    Feb 2009
    Location
    Temple, Texas
    Posts
    300

    Default 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.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •