This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 29 Next »

To use the Gmail connector, add the  <gmail.init>  element in your configuration before carrying out any other Gmail operations. The Gmail API uses OAuth2 authentication with Tokens. For more information on authentication, go to Authorizing Your App with Gmail.

init
<gmail.init>
	<userId>{$ctx:userId}</userId>
    <refreshToken>{$ctx:refreshToken}</refreshToken>
    <clientSecret>{$ctx:clientSecret}</clientSecret>
    <clientId>{$ctx:clientId}</clientId>
    <registryPath>{$ctx:registryPath}</registryPath>
    <accessToken>{$ctx:accessToken}</accessToken>
    <apiUrl>{$ctx:apiUrl}</apiUrl>
</gmail.init>
Properties  
  • accessToken: Value of the Access Token to access the Gmail REST API.

  • refreshToken: Value of the Refresh Token, which generates a new Access Token when the previous one gets expired.    

  • apiUrl The API URL of Gmail (https://www.googleapis.com/gmail).

  • userId: User mail ID.

  • clientSecret: Value of the Client Secret you obtained when you registered your application with the Gmail API.

  • clientId: Value of the Client ID you obtained when you registered your application with Gmail API.
  • registryPath: Registry Path of the connector where the Access Token will be stored. (If not provided, the connector stores the Access Token in the connectors/Gmail/accessToken Registry Path).

Creating the Client ID and Client Secret

Follow the steps below to obtain a Client ID and Client Secret for your Gmail account.

  1. Navigate to Google API Credentials and select your Gmail account to log in using that, to create an App to connect with the Gmail API.
  2. Click Select a Project and click NEW PROJECT, to create a project. Alternatively, you can use an existing project.

  3. Enter ConnectGmailAPI as the name of the project and click Create.

  4. Click Create credentials and click OAuth client ID.

  5. Click Configure consent screen in the next screen.

  6. Enter ConnectGmailAPI as the Product Name, and click Save.
  7. Enter the following details in the Create OAuth client ID screen and click Create.

    FieldValue
    Application typeWeb application
    NameConnectGmailClient
    Authorized redirect URIs (to get the code to request an AccessToken call to theGmail API.) https://developers.google.com/oauthplayground


    You view the Client ID and Client Secret you generated. 

  8.  Copy and keep the two links saved into a text file as you will need those for the next steps, and click OK.
  9. Click Library on the side menu, search for Gmail API and click on it.
  10. Click Enable to enable the Gmail API.
  11. Obtaing the Access Token and Refresh Token

Follow the steps below to automatically refresh the expired AccessToken and Refresh Token for your Gmail account, when connecting to Google API.

  1. Navigate to the OAuth 2.0 Playground and click OAuth 2.0 Configuration button.

  2. Select Use your own OAuth credentials, enter the Client ID and Client secret you created and click Close.
  3. Under Step 1, select Gmail API v1 from the list of APIs, select all the scopes listed under it, and click Authorize APIs.
  4. Select you Gmail account and click Allow, to grant the required permissions.
  5. Under Step 2, click Exchange authorization code for tokens to generate an display the Access Token and Refresh Token. 







  • After that


https://accounts.google.com/o/oauth2/auth?redirect_uri=http://hariprasathcsc.blogspot.com&response_type=code&client_id=1086713158210-0fdre9gn9nldoo653i71t3cu4estg1ob.apps.googleusercontent.com&scope=https://mail.google.com/+https://www.googleapis.com/auth/gmail.compose+https://www.googleapis.com/auth/gmail.insert+https://www.googleapis.com/auth/gmail.labels+https://www.googleapis.com/auth/gmail.modify+https://www.googleapis.com/auth/gmail.readonly+https://www.googleapis.com/auth/gmail.send&approval_prompt=force&access_type=offline

copy the above URL(need to replace the redirect_uri and client_id according to your app) into a browser and enter -> You need to log in with your email -> allow



After that, you will get a code with your redirect URI like,



  • For successful responses, you can exchange the code for an access token and a refresh token. To make this token request, send an HTTP POST request to the https://www.googleapis.com/oauth2/v3/token endpoint, and include the following parameters and the content-type should be application/x-www-form-URL encoded



Replace the code and clientId , clientSecret and redirectUri according to your app and send. From the response, you will get the accessToken and refreshToken.


Now that you have connected with Gmail REST API, use the information in the following topics to perform various operations with the connector.

  • No labels