DZone
Integration Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Integration Zone > Connecting Google Spreadsheet APIs With Mule ESB

Connecting Google Spreadsheet APIs With Mule ESB

Google's API lets you communicate with their integration services. Learn to configure and connect Mule ESB with Google API, with code and a video tutorial.

Jitendra Bafna user avatar by
Jitendra Bafna
CORE ·
May. 02, 17 · Integration Zone · Tutorial
Like (2)
Save
Tweet
7.17K Views

Join the DZone community and get the full member experience.

Join For Free

Google provides an Application Programming Interface which allows you to communicate with Google services and their integration services. It is useful for a third-party to take advantage of APIs and can even extend the functionalities of APIs. Examples of these include Search, YouTube, Google Spreadsheet, Google Maps, Google Contacts, etc. Google APIs require authentication and authorization using OAuth 2.0.

Mule ESB has capabilities to connect Google APIs and it provides various connectors to connect the Google APIs and perform the operations that you need. Below is a list of connectors available in Anypoint Exchange to connect Google APIs.

  • Google Spreadsheets Connector.

  • Google Contacts Connector.

  • Google Tasks Connector.

  • Google Calendar Connector.

  • Google Prediction Connector.

  • Google Contacts RAML.

  • Google Drive RAML.

Image title

In this article, you will see Google Spreadsheets Connector. Google Spreadsheets Connector provides instant API connectivity to Google Spreadsheets APIs, which allows you to create, modify, or access Google docs using OAuth 2.0 authentication. For more details on Google Spreadsheets API, click here.

By default, you will not find Google Spreadsheets Connector in your Anypoint Studio, so you can install the connector from Anypoint Exchange.

The first thing you need to do is authorize the operation to generate the token.

  <google-spreadsheets:config-with-oauth name="Google_Spreadsheets" consumerKey="${gs.clientid}" consumerSecret="${gs.clientsecret}" doc:name="Google Spreadsheets" scope="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://spreadsheets.google.com/feeds https://docs.google.com/feeds https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email">
        <google-spreadsheets:oauth-callback-config domain="${oauth.host}"   path="oauth2callback" async="true"/>
    </google-spreadsheets:config-with-oauth>
Fields Description
consumerKey The OAuth consumer key. It can obtain from the Google developer console.
consumerSecret

The OAuth consumer secret. It can obtain from the Google developer console.

scope

https://www.googleapis.com/auth/userinfo.profile

https://www.googleapis.com/auth/userinfo.email

https://spreadsheets.google.com/feeds

https://docs.google.com/feeds

https://www.googleapis.com/auth/spreadsheets.readonly

https://www.googleapis.com/auth/spreadsheets

Access Token URL

The URL defined by the Service Provider to obtain an access token.

Value: - https://accounts.google.com/o/oauth2/token

Authorization URL

The URL defined by the Service Provider where the resource owner will be redirected to grant authorization to the connector.

Value: - https://accounts.google.com/o/oauth2/auth

Callback URL It is made up of the domain, local port, remote port, and path. Example: http://localhost:3000/oauthcallback. 
This URL also needs to add under redirect URIs in the Google developer console.

Image title

Configuration Reference 

Image title

Authorizing the operation will return tokenID, and it can be read using flow variable  #[flowVars['OAuthAccessTokenId']] 

Once authorization is successful, you can use any operation to be performed depending on your requirement; make sure you are sending the token with every request to Google Spreadsheets APIs.

Image title

Image titleSometimes there can be a case when you need to use the authorized operation in one flow and another operation in other flow. In such a case, you need to use object store to store the tokenID generated during authorize operation to retrieve from the object store in other flow.

Code

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:context="http://www.springframework.org/schema/context" xmlns:google-spreadsheets="http://www.mulesoft.org/schema/mule/google-spreadsheets" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/google-spreaadsheets http://www.mulesoft.org/schema/mule/google-spreadsheets/current/mule-google-spreadsheets.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/google-spreadsheets http://www.mulesoft.org/schema/mule/google-spreadsheets/current/mule-google-spreadsheets.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <google-spreadsheets:config-with-oauth name="Google_Spreadsheets" consumerKey="${gs.clientid}" consumerSecret="${gs.clientsecret}" doc:name="Google Spreadsheets" scope="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://spreadsheets.google.com/feeds https://docs.google.com/feeds https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email">
        <google-spreadsheets:oauth-callback-config domain="${oauth.host}"   path="oauth2callback" async="true"/>
    </google-spreadsheets:config-with-oauth>a
    <flow name="google-spreadsheet-apiFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/authorize"  doc:name="HTTP" allowedMethods="GET"/>
        <google-spreadsheets:authorize config-ref="Google_Spreadsheets" doc:name="Google Spreadsheets" accessTokenUrl=" https://accounts.google.com/o/oauth2/token" authorizationUrl="https://accounts.google.com/o/oauth2/auth"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <google-spreadsheets:get-all-cells-as-csv config-ref="Google_Spreadsheets" lineSeparator="|" spreadsheet="Employee" worksheet="Employee" accessTokenId="#[flowVars['OAuthAccessTokenId']]" doc:name="Google Spreadsheets"/>
        <logger message="data fetched. #[payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>


References

  • Google API Commons: https://github.com/mulesoft/google-api-commons
  • Google Calendar: https://github.com/mulesoft/google-calendar-connector
  • Google Contacts: https://github.com/mulesoft/google-contacts-connector
  • Google Cloud Messaging: https://github.com/mulesoft/google-cloud-messaging-connector
  • Google Drive: https://github.com/mulesoft/google-drive-connector
  • Gmail: https://github.com/mulesoft/gmail-connector
  • Google Prediction: https://github.com/mulesoft/google-prediction-connector
  • Google Spreadsheets: https://github.com/mulesoft/google-spreadsheets-connector
  • Google Tasks: https://github.com/mulesoft/google-tasks-connector

Now, you know how to connect Google APIs With Mule ESB.

Here is the video tutorial:


Google Contacts Enterprise service bus Connector (mathematics) Google APIs authentication

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Regression Testing: Significance, Challenges, Best Practices and Tools
  • Learn the Weekly Rituals You Should Master as a Software Project Manager
  • Automation Testing vs. Manual Testing: What's the Difference?
  • 8 Must-Have Project Reports You Can Use Today

Comments

Integration Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo