Introduction
MuleSoft has introduced different Google Connectors to integrate with different Google services. Here is the snapshot of the existing connectors.

In this Blog We will see how we can integrate Google Drive Conector with Mulesoft.
Let's get started.
Google Cloud Platform Configuration
- First you have to create Google Cloud configuration for your Gmail.in my case I am using muletest.dec@gmail.com
- Go to Google API console.
https://console.developers.google.com/
- Select the check box and Agree condition

- Create New Project By providing Name

- Next

After you create your project you will see this page.

- Go to Credentials
- Click on Create Credentials
- Select OAuth Client ID

If you receive an error like to setup OAuth Concent Screen.Please follow as below.

- Click on configure Consent Screen and Select External as we are not Google Workspace developers.
- Click on Create then follow the page details




- Click on Save and Continue.
- Now again try to click on Create Credentials .This time it will ask you for application Type. Select Web Application




Mark this redirect URI somewhere we need to use this in MuleSoft.
Once you click on Create It will Provide Client_Id and Client_Secret .
Save this somewhere or Download as Json we have to configure these details in MuleSoft Connector Configuration.

Enable Google Drive API
- We have to Enable Google Drive API as well.
- Go to API Library if you were not there in that screen. Search for Google Drive API.
- Click on Enable.

Anypoint Studio Configuration
- Open Anypoint Studio
- Create New Project as MuleGoogleDriveDemo.
- Once it is create click on Ad dModule from Exchange and (login into your cloudhub account if not already logged in).
- Search for Google and add Google Drive Connector.

Below is the list of operations that MuleSoft Google Drive Connector Will Provide


Let's try to see Drive Files List operation in this blog.
Let's see what is available in my drive first .

I have these 3 drives and more in this drive lets try to get this by using muleSoft Connector.
Before that we have to configure the connector in muleFlow.
I will create one Http Listener to initiate the flow and then lets drag and drop the Google Drive Connector and start configuring it.
http://localhost:8081/googledrivetest

- Consumer Key : Client_Id which we have created in Google Console>
- Consumer Secret : Client_Secret which we have created in Google Console>
- Callback path: Give it like /callback
- Authorize Path : Give it like /authorize
- External callback URL : http://localhost:8081/callback (Same as we configured in Redirection URLs of Google Console Project)
- Access Token URI : https://oauth2.googleapis.com/token (You can get this from the Json file you downloaded earlier)
- Resource Owner ID : <give any name> - you should use this while testing
- Add on Dataweave to display payload as Json and deploy to test this.
- Save and Deploy this application.
- Once this Application is deployed first go to any browser and authorize your gmail using your Authorize URL along with ResourseOwnerID
http://localhost:8081/authorize?resourceOwnerId=test
- It will ask you to login into your Gmail account with which you have created Project in Google Console or the Test Users you have added in Google console project

Select all the roles and accesses that you wan to allow and click on Continue.You will receive response like "Successfully retrieved access token"

Now you can test your Actual Endpoint URL to get Google Drive List and hit in browser along with resourseOwnerID as query parameter using the same browser.

Done .Now we have successfully integrated Google Drive connector in MuleSoft
How to Fix possible Errors
- OAuth authorization dance not yet performed for resourceownerid null
or
How to Connect to Google Drive connector with OAuth2.0
Fix:
- Please check if you have given any resourseownerid value in configuration and use the same as query param while getting /authorize and your url.
- Don't forget to hit /authorize endpoint first before calling your actual URL along with resourseOwnerId.
- If you are using OAuth2.0 header in Postman use this below details to generate token.

- Click on Generate Access Token.
- It will ask to login into your gmail account and allow access.
- Once you click on Allow it will generate accesstoken.


- Click on Use Token it will get added to header.
- Now test your Actual API URL along with ResourceOwnerID with this token as Authorization.
http://localhost:8081/googledrivetest?resourceOwnerId=test
2. Request returned status code 403 - Access Denied
If you got this error while generating token using Postman follow below fix.
- First verify if you have enabled Google Drive API in Library.
- Try to create API Key in the google console for your Project as below by clicking on Client Credentials and select API KEY.

3. Add the user email address in the TEST Users section of OAuth Consent Screen.

Now Test the scenario again you will get it done.
