Setup Google Account for Google Drive API Walkthrough

A software developer had trouble getting started using Chilkat with his application for Google Drive. He gave me his login/password to help get him started. This blog post is a recording of the steps I’ve taken to set things up on the Google side to allow an application to access Google Drive files using a Client_ID and Client_Secret.

A Client_ID/Secret implies that the developer will need to create a Project in Google. Once created, we may need to generate keys.

Step 1: Log in to the Google Account and get our Bearings

Ok, I logged into the customer’s Google account. (I notify the customer before doing so, just so he knows exactly when I’m working on it, and I notify the customer when I’m finished.) Often logging in requires the customer to allow it because Google will send a text message or some other notification indicating a login from an unknown device…

OK.. so the login is OK, and I go to Google Drive and see 2 JPG files and a Getting Started PDF that was created by Google. When I run my test application, my goal is to see these 2 JPG files listed..

Step 2: Possibly Create an Project in Google

We may need to create a Project in Google to correspond to our actual application written in some programming language (VB6, C#, C++, Perl, Java, Ruby, …) which uses Chilkat.

I go to https://console.developers.google.com/?authuser=1 The top right portion of the web page looks like this:

Notice the “My Project” dropdown at the top of the web page, just to the left of the “Google APIs” logo. This shows the currently selected project. Google likely automatically added the “My Project”. You may create a new project by clicking on the dropdown and following the links. I’ll use “My Project” for my testing..

Step 3: Enable the Google Drive API

I find that the customer already enabled the Google Drive API. That’s good. If it’s not enabled, then click on the “Enable API” link, find Google Drive, and enable it.

Step 4: Do we have Credentials Setup?

Click on the “Credentials” link in the left rail. I find 2 credentials already created: One listed under “API Keys”, and the other listed under OAuth 2.0 client IDs. Here’s a screenshot. I omitted most of the API key for security. The client ID does not need to be kept secret.

We’ll need an OAuth 2.0 client ID, but it must be the correct type. We won’t be using anything listed under the “API keys”. In this case, the Client ID named “Other client 1” has the type “other”, and is not the type of Client ID we need.

Even though our application may not be a web app, we’ll still need an OAuth client ID for a web application. (Our application could be a desktop app, such as C#, VB6, Delphi, C++, Java, etc., or it could be a script in Perl, Python, PHP, Ruby, VBScript, etc.)

Step 5: Create Credentials of the Correct Type.

Click on the Create Credentials dropdown and choose OAuth client ID.

As shown below, choose “Web application” (even though your app is a desktop app or script), and add an Authorized redirect URIs using “localhost”, such as “http://localhost:55568/”.   The 55568 is a port number.  You may choose any port that is likely not already used on the system.  Choose a port in the ephemeral port range.  Note: The redirect URL must end in a “/”.  Do not use “https”, use “http”.  (This is not a security issue because the callback is from the browser to  your app running on the same system.)

Looking at our credentials again, we can see the Client ID we just created:

Step 6: Get the Client ID and Client Secret.

Click on “Chilkat test 1” to get the Client ID and Client Secret.  These are the strings we’ll need to fetch an OAuth2 access token.  We’ll only need to fetch it once.  The access token can be saved to a file, database, etc. and then used with our API calls, even for the next time we run our application.  In other words, you may persist the access token.

Step 7: Use the Client ID and Client Secret to get an Access Token.

Here’s sample code demonstrating how to do it:

C: Google OAuth2 Access Token
Chilkat2-Python: Google OAuth2 Access Token
C++: Google OAuth2 Access Token
C#: Google OAuth2 Access Token
DataFlex: Google OAuth2 Access Token
Delphi ActiveX: Google OAuth2 Access Token
Delphi DLL: Google OAuth2 Access Token
.NET Core C#: Google OAuth2 Access Token
Excel: Google OAuth2 Access Token
Visual FoxPro: Google OAuth2 Access Token
Java: Google OAuth2 Access Token
Lianja: Google OAuth2 Access Token
MFC: Google OAuth2 Access Token
Mono C#: Google OAuth2 Access Token
Node.js: Google OAuth2 Access Token
Objective-C: Google OAuth2 Access Token
Perl: Google OAuth2 Access Token
PHP ActiveX: Google OAuth2 Access Token
PHP Extension: Google OAuth2 Access Token
PowerBuilder: Google OAuth2 Access Token
PowerShell: Google OAuth2 Access Token
PureBasic: Google OAuth2 Access Token
Python: Google OAuth2 Access Token
Ruby: Google OAuth2 Access Token
Swift: Google OAuth2 Access Token
Tcl: Google OAuth2 Access Token
Unicode C: Google OAuth2 Access Token
Unicode C++: Google OAuth2 Access Token
Visual Basic 6.0: Google OAuth2 Access Token
VB.NET: Google OAuth2 Access Token
VBScript: Google OAuth2 Access Token
Xojo Plugin: Google OAuth2 Access Token

Step 8: Use the Access Token in an API Call

C: List Files in Google Drive
Chilkat2-Python: List Files in Google Drive
C++: List Files in Google Drive
C#: List Files in Google Drive
DataFlex: List Files in Google Drive
Delphi ActiveX: List Files in Google Drive
Delphi DLL: List Files in Google Drive
.NET Core C#: List Files in Google Drive
Excel: List Files in Google Drive
Visual FoxPro: List Files in Google Drive
Java: List Files in Google Drive
Lianja: List Files in Google Drive
MFC: List Files in Google Drive
Mono C#: List Files in Google Drive
Node.js: List Files in Google Drive
Objective-C: List Files in Google Drive
Perl: List Files in Google Drive
PHP ActiveX: List Files in Google Drive
PHP Extension: List Files in Google Drive
PowerBuilder: List Files in Google Drive
PowerShell: List Files in Google Drive
PureBasic: List Files in Google Drive
Python: List Files in Google Drive
Ruby: List Files in Google Drive
Swift: List Files in Google Drive
Tcl: List Files in Google Drive
Unicode C: List Files in Google Drive
Unicode C++: List Files in Google Drive
Visual Basic 6.0: List Files in Google Drive
VB.NET: List Files in Google Drive
VBScript: List Files in Google Drive
Xojo Plugin: List Files in Google Drive