PHP API Tutorials

How to generate access token in Google API using PHP ?

Today I will show you how to generate access token for accessing google services using

Google API PHP library

. Its a very simple task.  Google , world’s largest giant ever providing a variety of quality services.

Steps to create Access Token for accessing Google API Services and locating Google API PHP Library.

Step1 : Download Google PHP Library  (Google API Library downloading using PHP)

For downloading Google API Library you have download composer first which is available freely on https://getcomposer.org/ . After downloading run  CMD (Command Prompt) make sure you have run it as Administrator. You will see a window like below

Mongo DB Installation Windows Screen Shot 8

Now move to path where you want to download Google API Library using commands like below

  • “cd..” (for moving to upper level directory)
  • “cd” foldername (for moving in directory)

Now type command “composer”  excluding quotes then you will see

Google Map

If you see window like above then composer is installed successfully.  After that you have to run below command exactly Just copy and paste using mouse on cmd.

composer require google/apiclient:^2.0

Downloading will start  as shown below

Google Map API

Once all processes completed you will see window below

Google API Library is downloaded successfully. A folder will be shown in drive which you have chosen for downloading. Its may be name as “vendor”. Copy that folder to your localhost directory of your website or your online server using FTP or Filezilla.

Step2 : Create a file devildoxx.analytics.php or any other name with extension .php

Step3 : Edit the file you created and include autoload.php  file available in vendor folder. Code in devildoxx.analytics.php will look like below

<?php

include ("vendor/autoload.php");

?>

Step4 : Login to Google console using your Gmail Id

Step5 : Create a Project in Google Console

Step6 :  Once your project is created you will see option for Credentials in right sidebar Click on that

Step7 :  Now you will be asked to generate credentials

Step8 :  Choose OAuth Client ID and then choose web application

In above redirect url will be same path to that file which we created in Step 2.

Step9 : Click create and then pop window will be open

Copy both client id and client secret key.

Step10 : Now open devildoxx.analytics.php file in editor and paste the following code in it.

Tags

Anil Mehra

I am Anil Mehra, a passionate, workaholic and a Full Stack Tech Savvy Programmer with true north towards growth. I have worked on 256 live projects in MNC. I am expertise in the field of Programming, Server Management, SEO, Blogging and SMO...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button