Exports a Google Doc to the requested MIME type and returns the exported content. Please note that the exported content is limited to 10MB.
(Export only supports Google Docs) See https://developers.google.com/drive/v3/web/manage-downloads for a list of MIME types.
LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL lnStatusCode
LOCAL loSbErrResponse
LOCAL loRespBodyStream
loRest = CreateObject('Chilkat_9_5_0.Rest')
* Provide a previously obtained OAuth2 access token.
loOauth2 = CreateObject('Chilkat_9_5_0.OAuth2')
loOauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loRest.SetAuthOAuth2(loOauth2)
lnSuccess = loRest.Connect("www.googleapis.com",443,1,1)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loOauth2
CANCEL
ENDIF
loRest.AddQueryParam("mimeType","application/pdf")
* First send the HTTP request.
lnSuccess = loRest.SendReqNoBody("GET","/drive/v3/files/1zvzpTHO1dM9vNKYxpmr4YrX7x_R6qiNGFb8WB8h9wuI/export")
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loOauth2
CANCEL
ENDIF
* Read the response header. If the response status code is success, stream to the file.
* Otherwise receive the error response text.
lnStatusCode = loRest.ReadResponseHeader()
IF (lnStatusCode < 0) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loOauth2
CANCEL
ENDIF
IF (lnStatusCode <> 200) THEN
? "Received error response code: " + STR(lnStatusCode)
* Read the error response body.
loSbErrResponse = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.ReadRespSb(loSbErrResponse)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loOauth2
RELEASE loSbErrResponse
CANCEL
ENDIF
? "Error response:" + loSbErrResponse.GetAsString()
RELEASE loRest
RELEASE loOauth2
RELEASE loSbErrResponse
CANCEL
ENDIF
* Stream the response body to the output file.
loRespBodyStream = CreateObject('Chilkat_9_5_0.Stream')
loRespBodyStream.SinkFile = "/someDirectoryPath/test.pdf"
lnSuccess = loRest.ReadRespBodyStream(loRespBodyStream,1)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loOauth2
RELEASE loSbErrResponse
RELEASE loRespBodyStream
CANCEL
ENDIF
? "Example Completed."
RELEASE loRest
RELEASE loOauth2
RELEASE loSbErrResponse
RELEASE loRespBodyStream