on 2024 Sep 04 6:36 AM
Hi Gurus,
I have some files stored in a google drive and I want to access these files from SAP using ABAP. I have created the client id and secret and also tested the authentication token with postman and it seems to be working fine in Postman. Now my question is that how to call the google drive API like "https://www.googleapis.com/drive/v3/files" from SAP using ABAP. Also how to get the auth token.
I have found one resource which talks about the same but I am not able to achieve it as SAP blocks HTTPS communication with google without SSL and we don't have the signed SSL certificate for it. Also do I need ABAP SDK for google cloud for achieving this?
Resource -> https://cloud.google.com/solutions/sap/docs/abap-sdk/on-premises-or-any-cloud/latest/authentication-...
Is there any way to communicate without SSL or by using HTTP rather than HTTPS?
Kindly help with this.
Request clarification before answering.
@MadhavSharma ....you can use ABAP SDK for Google Cloud to invoke any Google APIs natively from ABAP using HTTP, including Drive API. ABAP class /GOOG/CL_DRIVE_V3 method EXPORT_FILES in the SDK let's you get file contents of a file stored on Google Drive.
Prerequisites to this is installation and configuration (SAP Security, SDK Config) of the ABAP SDK for Google Cloud. You can use OAuth 2.0 based authentication option in the SDK to invoke Drive API (detailed steps with examples in the blog article linked at last).
Here is a code snippet....EXPORT_FILES method returns the file contents in xstring format....which you can convert to readable string using SAP standard function modules.
DATA:
lv_q_mimetype TYPE string,
lv_p_file_id TYPE string,
lv_filedata TYPE xstring.
TRY.
* Open HTTP Connection
DATA(lo_client) = NEW /goog/cl_drive_v3( iv_key_name = '<ABAP SDK Client Key>' ).
* Populate relevant parameters
lv_q_mimetype = '<Mime Type of the File>'.
lv_p_file_id = '<File ID of the file>'.
* Call API method: drive.files.export
CALL METHOD lo_client->export_files
EXPORTING
iv_q_mimetype = lv_q_mimetype
iv_p_file_id = lv_p_file_id
IMPORTING
es_raw = lv_filedata
ev_ret_code = DATA(lv_ret_code)
ev_err_text = DATA(lv_err_text)
es_err_resp = DATA(ls_err_resp).
IF lo_client->is_success( lv_ret_code ).
MESSAGE 'Success' TYPE 'S'.
* Convert lv_filedata (in xstring) to string to get file data
ELSE.
MESSAGE lv_err_text TYPE 'E'.
ENDIF.
* Close HTTP Connection
lo_client->close( ).
CATCH /goog/cx_sdk INTO DATA(lo_exception).
MESSAGE lo_exception->get_text( ) TYPE 'E'.
ENDTRY.
ABAP SDK let's you invoke other Workspace APIs too, like Gmail, Sheets, Chat, etc., refer to the blog article here to know more.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 17 | |
| 8 | |
| 8 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.