VB6 usage of V2 Calendar API via Http - the easiest way to migrate is REST?

302 views
Skip to first unread message

Martin Teefy

unread,
Oct 13, 2014, 8:43:59 AM10/13/14
to google-ca...@googlegroups.com
Hi,

I've been using the calendar v2 via HTTP Post/get quite happily for years and now need to migrate but instead of creating VB.net dll to call from VB6 i'd like to continue to call the API directly via Http
but all the developer pages are discussing .NET library usage?

I really do not want to use InterOp calls to .Net unless i really have to....

Does anyone have an example of the REST/OAuth2 usage to replace the current code:

Function GooAuthentification(stEmail As String, stPassword As String) As Boolean

Dim stURl As String
Dim stSource As String
Dim stFormData As String
Dim stHeaders As String
    
    stSource = App.CompanyName & "-" & App.EXEName & "-" & App.Major & "." & App.Minor
    stFormData = "Email=" & stEmail & "&Passwd=" & stPassword & "&source=" & stSource & "&service=cl"
    stHeaders = "Content-Type:application/x-www-form-urlencoded GData-Version: 2.1"
    
    mInet.Execute stURl, "POST", stFormData, stHeaders
    
    bFinAttente = False
    Do Until bFinAttente = True
        DoEvents
    Loop
     
    FrmDebug.txtResponse = "Authentication Response:" & _
                            vbCrLf & vbCrLf & _
                            stReponse
        
    If InStr(1, stRetHeader, "200 OK") > 0 Then
        stAuthCode = Right(stReponse, Len(stReponse) - InStrRev(stReponse, "Auth=") - 4)
        GooAuthentification = True
    Else
        GooAuthentification = False
    End If

End Function

Function GooEnvoi(stCde As String, stURl As String, Optional stFormData As String = "", Optional stETAG As String = "") As Boolean
    
    Dim stHeaders As String

    Select Case stCde
        Case "DELETE", "PUT"
            stHeaders = "Authorization: GoogleLogin auth=" & stAuthCode & _
                        "Content-Type:application/atom+xml" & vbCrLf & _
                        "GData-Version: 2.1" & vbCrLf & _
                        "If-Match: " & stETAG
        Case Else
            stHeaders = "Authorization: GoogleLogin auth=" & stAuthCode & _
                        "Content-Type:application/atom+xml" & vbCrLf & _
                        "GData-Version: 2.1"
    End Select
    
    bFinAttente = False
    mInet.Execute stURl, stCde, stFormData, stHeaders
    Do Until bFinAttente = True
        DoEvents
    Loop
    GooEnvoi = Mid(stRetHeader, 10, 2) = "20" ' ("HTTP/1.1 201 Created" ou "HTTP/1.1 200 OK" )
        
End Function

Pete M

unread,
Oct 16, 2014, 4:12:46 AM10/16/14
to google-ca...@googlegroups.com
Hi Martin,

I was in the same position as you but using vb net to handle api v2. I got very confused with all the library examples and found it very straight forward to use REST instead and call it thru the net webrequest, I presume you can pass http calls directly from vb6? The authorisation took a bit of working out but the individual webrequests to create/delete/insert events is fairly easy with one bit of help from Lucia because I overcomplicated things.

Pete
Reply all
Reply to author
Forward
0 new messages