How to manually generate a Google Drive Token

How to manually generate a Google Services Token?

A token-based authentication system allows users to enter their username and password in order to obtain a token, which allows them to fetch a specific resource, without using their username and password. Once their token has been obtained, the user can offer the token, which offers access to a specific resource for a time period, to the remote site.
This article explains how to generate a Google Services token, step by step, with the needed permissions for the COZYROC REST Connection Manager component. And it explains how to generate a token for the different Google Services.


In order to use the generated token, you need to create a specific XML file, which then needs to be entered into the REST Connection Manager Configuration. To simplify this article, the process has been separated into 4 steps:

1) Generate authorization code and give permission to COZYROC to access your Google Service
2) Create a custom POST request to be sent to the Google server
3) Receive the authorization and refresh token in JSON format so that you can examine the result from the response
4) Create an XML file for the token that complies to the COZYROC token XML format


Step 1: Generate authorization code and give permission to COZYROC to access your Google Service

We have prepared a separate URL for each different Google Service, that is going to be used to grant COZYROC permissions to access your Google Service(Google Drive, Google Tasks, Google Sheets and etc..) 

Google Service
 URL
Google Drive
Google Tasks
Google Analytics
Google Calendar
Google Sheets
GoogleBigQuery


For explanation which parameters you need and the value you need for each parameter please look at the table below. Table below shows the parameters and their value for Google Drive token. You will find those parameters and values in the URLS above.


Parameters
Value
client_id
822955360540k56u5vu2ssvivg9qno2oisml9322esj.apps.googleusercontent.com


redirect_url

http%3A%2F%2Flocalhost
scope
https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.
googleapis.com%2Fauth%2Fdrive.readonly%20https%3A%2F%2Fwww.googleapis.com
%2Fauth%2Fdrive.appfolder%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.
file%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.install%20https%3A%2F%2Fwww.
googleapis.com%2Fauth%2Fdrive.metadata%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2F
drive.metadata.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.
readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.scripts
access_type
offline


  1. Based on what Google Service token you want to create, Click the URL above for the particular Google Service and then the following screen will open:
           
            
  1. Then enter your credentials and you will get the following screen:
           
  1. Click the "Allow" button in the above screen to grant permissions to COZYROC to access your Google Service, in our case Google Drive. As a result, a link will be generated, that includes the authorization code that we are going to need in Step 2.
          In our case the following link gets generated:
       You are  going to need the value of the code parameter from the generated URL and, in our case, this value is:
                    

code=4/zgFa2OjKFvuYkxqHDBvGZ9xlp2TEVRJhsA_Kp6s2chwV3fhiImh6o8iUzfyuVlVInWiLJEcEGjAwUcoh7gEL5-0
You can use this code for only a single request and it will expire in 5 minutes or less.

Step 2: Create a custom POST request to be sent to the Google server

  In this step, we are going to create a POST URL that needs to be sent to the Google Server. In order to do that, we will be using POSTMAN. You can use any software that will allow you to do that.

In the following table, you can find all the Post request parameters that you are going to need and their values. 
  

 Parameter
   Value
Notes
grant_type
authorization_code

You should use this value
 client_id
822955360543-0k56u5vu2ssvivg9qno2oisml9322esj.apps.googleusercontent.com
You should use this value
redirect_uri
http://localhost/
You should use this value
client_secret
Em0SYyJ09-NgLvhyT2hPOlfY
You should use this value
code
4/zgFa2OjKFvuYkxqHDBvGZ9xlp2TEVRJhsA_Kp6s2chwV3fhiImh6o8iUz
fyuVlVInWiLJEcEGjAwUcoh7gEL5-0
In my case, the Code value will be: 4/zgFa2OjKFvuYkxqHDBv
GZ9xlp2TEVRJhsA_Kp6s2chwV3fhiImh6o8iUz
fyuVlVInWiLJEcEGjAwUcoh7gEL5-0. It will be a different value for you. Please look at the information above.

To create a new POST Request by POSTMAN please follow the steps:
  1. Login to POSTMAN
  2. Click the button "New" and select "Request" from the dropdown menu. Please look at the screenshot below:

  3. Enter request name and save your request.
  4. Open your request, select POST for the Request and enter for URL: "https://oauth2.googleapis.com/token". This is the URL where we are going to send the Post Request. Please look at the screenshot below:

  5. Click "Body" 
  6. Select "x-www-form-urlencoded
  7. Enter for Key and Value all the Post request parameters and their values we showed you in the table above. Please look at the screenshot above
  8. You will also need to set up the Headers as Content-Type = application/x-www-form-urlencoded. Please look at the POSTMAN screenshot below:

  9. Then click "Send" to send the POST Request
Once you send the Post request you will get a response in JSON format. 

Step 3: You will receive the authorization and refresh token in JSON format. You will need to examine the result from the response.
If the operation is successful, you will get a response similar to the following in JSON Format:

{
  "access_token""ya29.a0Ae4lvC1ZqXVJXpwFHVY7-dWu9a1_6HuJQovLf16docSDIU0PThJQ1NgIufBAY2dVqzeYuruc4QVwHpMwY1tuspj4qo2JAQ_8xibmmHTdiDxlk0bNkl2EaJH1l7UcKZUOMdvH8pC9gPKBQU0mahLrHHGsah3VvL7PN3M",
  "expires_in"3599,
  "refresh_token""1//0dFnlTD2PccEjCgYIARAAGA0SNwF-L9IrdAiKWj7zFCGXBNRYywpv_LYL48JTsWCWDGioq216Ao9mCKM36p8anjdtzbnXw0EBde4",
  "token_type""Bearer"
}

If you don't get the response, examine your process for errors and fix them.
We will use the access_token value and the refresh_token values in the next step to create the XML Token File.

Step 4: Create an XML file for the token that complies with the COZYROC token XML format
  1. Go to your REST Connection Manager and click on it twice; the REST Connection Manager configuration screen will open.
  2. Select  your Google Service for Configuration, in our case this is "Google Drive" . Please look at the screenshot below:

  3. Click the button "New" to create a new token file.
  4. Complete all the steps until you get to the third page of the Wizard. Please look at the screenshot below:


  5. For "Access Token", enter the access_token value from the JSON Response you received above.
  6. For "Refresh Token", enter the refresh_token value from the JSON Response you received above.
  7. For "Expiration(UTC):", keep the default Expiration date and time value that was automatically calculated(Current UTC date and time + 50 minutes ) 
  8. For "Save Files:", enter the file token name and the file path where you want to save the newly generated Token XML File.   
  9. For "Password:", enter a token password. Please look at the screenshot below:
  10.   
  11. Click the "OK" button. Your token XML file will be generated. Please look at the screenshot below:

  12. Click the "Test Connection" button and you should get the message "Test connection succeeded".

    Book a Presales Call


    Are you new to COZYROC and evaluating our solutions? 
    Book a Presales Call with us now and get 5% off SSIS+.
      • Related Articles

      • How to manually generate a Shopify Token?

        A token-based authentication system allows users to enter their username and password in order to obtain a token, which allows them to fetch a specific resource, without using their username and password. Once their token has been obtained, the user ...
      • Considerations when choosing REST token storage

        Since version 2.1 in COZYROC SSIS+ access tokens used by REST Connection Manager can be stored not only in the file system, but also in a database (SQL Server).   Using such a centralized storage addresses the following complications with the ...
      • How to upload an Excel file to Google Drive as a Google Spreadsheet

        In order to upload an Excel file to Google Drive as Google Spreadsheet you need to: Create a project in Visual Studio. To establish a Connection Manager to Google Drive, you need to use a Google Drive Connection (see Quick Start >> Establish ...
      • How to use a Database storage for new REST tokens

        Make sure you have launched Visual Studio as "Run as Administrator". 1 : In Rest Connection Manager choose the configuration from the dropdown list you want to generate token for. 2: For the Token storage parameter in the grid below select Database ...
      • How do I access Google Sheets in a Shared Google Drive?

        To access Google Sheets in a Shared Google Drive you have the following two options: Option 1: You should enter for "File Path" the Google Drive file's identifier. You will find the file identifier in the Google Sheets URL. Please look at the ...