B4J Question Problem Adding Event to Google Calendar

Discussion in 'B4J Questions' started by kostas_skarl, Apr 16, 2019.

  1. kostas_skarl

    kostas_skarl New Member Licensed User

    SOLVED. See next post for code.


    I have succesfully added a "quick event", but I am having difficulties when I try to add an "event" to Google Calendar, as I am getting the 400 error message: "Missing end time."

    I suspect that maybe the nested objects "start" and "end" are not correctly sent with the request.

    I have also tried using a map object and JSONGenerator, instead of putting my values directly to the HTTP Request, but I am getting the same error.

    Could someone please explain how to create this request?

    Thanks in advance for your help.


    Please find my code below:

    Code:
    Sub add_event
       
        oauth2.GetAccessToken
        
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
        
    If Success = False Then
            
    Log("Error accessing account.")
            
    Return
        
    End If
       
        
    Dim Summary, StartDateTime, EndDateTime As String
        
    Dim BaseURL As String = "https://www.googleapis.com/calendar/v3/calendars/primary/events"
       
        Summary=
    "My Summary"
        StartDateTime = 
    "2019-04-19T12:00:00-07:00"
        EndDateTime = 
    "2019-04-19T13:00:00-07:00"

        
    Dim j As HttpJob
        j.Initialize(
    "", Me)
        j.PostString(
    $"${BaseURL}/?access_token=${Token}"$ & " &summary='" & Summary & "'&start.dateTime='" & StartDateTime & "'&end.dateTime='" & EndDateTime & "'""")
        j.GetRequest.SetContentType(
    "application/json")
        
    Wait For (j) JobDone(j As HttpJob)
        
    If j.Success Then
            
    Log(j.GetString)

        
    Else
            
    Log(j.ErrorMessage)
            
    Log("Online data not available.")
        
    End If
        j.Release
    End Sub
     
    Last edited: Apr 16, 2019
  2. kostas_skarl

    kostas_skarl New Member Licensed User

    Sorry, problem solved...

    I tried the json format again more carefully.

    Code:
    Sub add_event
        
        oauth2.GetAccessToken
        
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
        
    If Success = False Then
            
    Log("Error accessing account.")
            
    Return
        
    End If
        
        
    Dim Summary, StartDateTime, EndDateTime As String
        
    Dim BaseURL As String = "https://www.googleapis.com/calendar/v3/calendars/primary/events"
        
        

        
        Summary=
    "My Summary"
        StartDateTime = 
    "2019-04-18T16:00:00-00:00"    'Europe/Athens
        EndDateTime = "2019-04-18T17:00:00-00:00"    'Europe/Athens
        
        
    Dim m As Map
        m.Initialize
        m.Put(
    "summary":Summary)
        m.Put(
    "start": CreateMap("dateTime":StartDateTime))
        m.Put(
    "end": CreateMap("dateTime":EndDateTime))

        
    Dim jgen As JSONGenerator
        jgen.Initialize(m)


        
    Dim j As HttpJob
        j.Initialize(
    "", Me)
        
    'j.PostString($"${BaseURL}/?access_token=${Token}"$ & " &summary='" & Summary & "'&start.dateTime='" & StartDateTime & "'&end.dateTime='" & EndDateTime & "'", "")
        j.PostString($"${BaseURL}/?access_token=${Token}"$,jgen.ToString )
        j.GetRequest.SetHeader (
    "Accept""application/json")
        j.GetRequest.SetContentType(
    "application/json")
        
    Wait For (j) JobDone(j As HttpJob)
        
    If j.Success Then
            
    Log(j.GetString)

        
    Else
            
    Log(j.ErrorMessage)
            
    Log("Online data not available.")
        
    End If
        j.Release
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice