View Contents Of Your Google Drive Using .NET

This article will describe how you can get the list of your documents from one drive. You can use multiple frameworks but I will use them. NET.

So, all you have to do is follow these steps.

First of all, we need to register our Application to Google Drive and for that, we need to create a new project on this link. After logging in with your account, you will be asked to agree to the terms and conditions. Click ‘Agree and continue’.

Google drive

After this, you will be able to enable the API.

API

You will be presented with the API manager. As you see here, you can mention here what type of credentials you need. It's better not to change these and click on the credentials.

API manager

This will take you to the following UI. Click ‘OAuth content screen’.

OAuth content screen

Here, you will be able to see your email address. You also need to mention the project name, shown to the user. I have selected ‘csharpcorner’. After this, hit save.

Csharpcorner

Click the credentials again and you will get this window. Click ‘Create credentials’ and then ‘OAuth client ID’.

Create credentials

Select ‘other and add the name ‘Drive API Quickstart’’

Drive API Quickstart

After that, you will be presented with the keys. Click OK and you will be able to see your keys. Click on download to download the key.

Credentials

At this stage, you are done with the ‘settings’ part. Now comes the programming part.

  • Create a Console Application project.
  • Add Nuget package  "Install-Package Google.Apis.Drive.v3".
  • Open program. cs and replace the code with the code attached.
  • Rename the download key from Google to the client_secret.json and add it to your project, you will see it like this.
    Install-Package

Right-click on the file click properties and change 'Copy to Output Directory' to "Copy Always"

Copy to Output Directory

Now, run the project and you will be routed to the Browser for authentication.

Browser for authentication

Once you allow it, you should be able to see your document list in the console.


Similar Articles