Sunday 24 April 2022

Google Drive API PHP | Display List Of Files From Google Drive On Browser



JQUERY Validator | Move Error Messages Anywhere On Web Page

-------------------------------

http://www.youtube.com/user/SanketRooney?sub_confirmation=1 


Facebook Page:- 
https://www.facebook.com/UnpossibleNS 

Twitter Account:- 
https://twitter.com/UnpossiblePOG 

Blog:- 
https://unpossiblepog.blogspot.com/ 

Website:- 
https://unpossiblepog.com/ 

Gaming Instagram:- (@unpog.gaming)
https://www.instagram.com/unpog.gaming/

-------------------------------

By the end of this video you will be able to get list of files from your google drive using PHP.

Let’s not waste the time, shall we?

Open the google and search “Google Drive API PHP”.

Open the developer.google.com site.

You have to have PHP version greater than 5.4.

Also, if you are using Windows OS, you can download the composer from this link.

For linux user, you have to enter the command “sudo apt install composer”.

You can find how to enable API, however sometimes google update this page, so this link won’t always be here.

So to enable the API, follow my steps.

On google, search “console cloud google”.

Go inside the link called “console.cloud.google.com”

From side menu, click on dashboard inside home.

Here, next to Google Cloud Platform, you will see one dropdown, click on it, create a new project.

Give it any random name.

Wait for project to be created.

After that, again click on dropdown and select the project that you recently created.

After that, open the side menu, and in APIs & Services, click on Credentials.

Click on CREATE CREDENTIALS, and OAUTH Client ID.

Initially you will have to configure the project.

Only the EXTERNAL USER TYPE is available, so click on it and click on CREATE.

Give any random APP NAME.

Select your email ID.

Scroll down.

Add any random domain.

You can even add google.com for now.

I have my own website so I am going to add it.

In Developer contact information, add your own email address.

Click on SAVE AND CONTINUE.

Add all the scopes available.

In test users, add your own email address for now.

Click on SAVE AND CONTINUE.

Now, we are ready to create credentials.

Again go to side menu, APIS and SERVICES, Credentials.

Click on CREATE CREDENTIALS, OAUTH CLIENT ID.

Select Web Application.

Give any name.

In Authorized JS Origins, you can add localhost’s IP address.

In, Authorized redirect URIs, you have to add the path which will display list of files in google drive.

I am using XAMPP, so in HTDOCS, I am going to create a folder.

Use the folder name next to ip address and then “quickstart.php”.

We shall later going to create a quickstart PHP file.

Once done, you will see CLIENT ID, click on it’s download icon.

Download the JSON.

Copy-paste that file inside google-drive folder which is inside HTDOCS folder of xampp.

Rename it to credentials.json file as given in code.

Open the command prompt, and reach to the google-drive folder by using CD commands.

Once reached, type the command as shown in document.

Wait for vendor file to download.

After that, create a quickstart.php file in that google-drive folder.

Paste the given code inside that file.

We shall change scope to DRIVE because in next video, we shall upload files from localhost to google drive.

Change the number of files that you want to list.

Go to google cloud platform, click on Library, search GOOGLE DRIVE API.

Enable the API.

Now run the command they provided in same command prompt.

It shall ask for verification code.

Mark the link and right click at the top of CMD, and copy it.

Paste it in browser’s URL.

Login with your email.

Actually I forgot to start XAMPP.

But it doesn’t matter.

Copy the value of CODE in URL up to the “&” before the SCOPE variable.
Paste it and you will see the list of files from google drive.

There is an error of count function which is caused because of the different version of PHP.

I shall fix that later.

First, I shall make it run on browser by starting Apache server from XAMPP.

Hit the URL which ends with quickstart.php

It is not allowing to run it on browser so the comment those lines from file.

You will be able to see files list.

Go to the file where COUNT function is created.

Wrap it’s argument inside an array and now the error is gone.
Like if that works for you, any doubts, comment them down below.
In next video, I am going to upload files from local server to google drive, so make sure to subscribe if you want to.
Thanks for watching.