Friday, November 29, 2019

Laravel PHP Create Folder and Upload file to google drive with access token

In this Laravel PHP tutorial, I will tell you how to upload file on Google drive using Google drive API.
I have already discussed about Login authentication with Google APIs, You can follow this link to get access token after successfully authentication with Google OAuth2 API.
For this example, I need refresh token for permanent access to Google APIs because Access token have limited lifetime that means you will have to repeat the OAuth 2.0 consent flow to authenticate user, but If you have refresh token then you can use this refresh token to obtain a new access token.
At the time of initial authorization request only, Google provide refresh token but to obtain refresh token you will have to specify offline access like this :
$this->gClient->setAccessType("offline");
$this->gClient->setApprovalPrompt("force");
You will have to enable Google Drive API with your Google account.
You need to have client_idclient_secret and api_key for this example.
Step 1 : Installation
First I will go with fresh installation by running following command :
composer create-project --prefer-dist laravel/laravel blog "5.4.*"
Step 2 : User Table
Now I will create User table to store token after authentication with Google for future access.
When you install fresh Laravel application then you will have migration file for users table by default in following path database/migrations.



Load disqus comments

0 comments