Hello,

I try to implement a ClientLogin in Excel VBA. I have attached the
test code that first retrieves successfully the Auth ID and then tries
to retrieve the calendar feed.
I can successfully retrieve the Auth ID with that code. But then when
I do the second request I always get This response:

Status:       401
StatusText:   Authorization required
ResponseText: <HTML>
<HEAD>
<TITLE>Authorization required</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Authorization required</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

I have also tried the following scenarios:
- Omit Authorization header: I get the same Error 401 response
- send invalid token: I get Invalid token response

So I think the google server is recognizing the authorization header
in some way. Why does it respond with "Authorization required" in both
cases if I add the authorization header and als if I omit it?

Best regards
Andreas

This is the code:

Private Sub SendenButton_Click()
    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    URL = "https://www.google.com/accounts/ClientLogin";
    objHTTP.Open "POST", URL, False
    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.0)"
    objHTTP.setRequestHeader "Content-type", "application/x-www-form-
urlencoded"
    objHTTP.send ("accountType=HOSTED_OR_GOOGLE&Email=" &
EmailTextBox.Text & "&Passwd=" & PasswordTextBox.Text &
"&service=cl&source=nikem-excelcal-1.0")

    Debug.Print "ClientLogin"
    Debug.Print "Status:       " & CStr(objHTTP.Status)
    Debug.Print "StatusText:   " & objHTTP.StatusText
    Debug.Print "ResponseText: " & objHTTP.ResponseText



    Dim token
    token = Right(objHTTP.ResponseText, Len(objHTTP.ResponseText) -
InStr(objHTTP.ResponseText, "Auth=") - 4)
    token = Left(token, Len(token) - 1)

    Debug.Print "token:        " & token

    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    URL = "https://www.google.com/calendar/feeds/default/private/full";
    objHTTP.Open "GET", URL, False

    objHTTP.setRequestHeader "Authorization", "GoogleLogin auth=" &
token & ""
    objHTTP.setRequestHeader "GData-Version", "2"
    objHTTP.setRequestHeader "Content-Type", "application/atom+xml"
    objHTTP.send ("")

    Debug.Print "allcalendars"
    Debug.Print "Status:       " & CStr(objHTTP.Status)
    Debug.Print "StatusText:   " & objHTTP.StatusText
    Debug.Print "ResponseText: " & objHTTP.ResponseText

    ResultLabel.Caption = CStr(objHTTP.Status) & vbCrLf &
objHTTP.StatusText & vbCrLf & objHTTP.ResponseText

End Sub

-- 
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html

Reply via email to