Tutorial: Create Application with Google APIs and OAuth 2

Now that you understand the basics of Google OAuth 2, let’s build a simple application that uses OAuth 2.0 for connecting to Google API’s on user’s behalf.

  1. Go to console.developers.google.com and create a new project.

Create Google Cloud Project

  1. Give your project a name.

Project

  1. Go to Library, search for the Google APIs that you wish to use in your application and enable them one by one.

enable-gmail-api

  1. Go to Credentials -> Create Credentials -> Oauth Client Id. We’ll discuss service accounts in a later chapter.

oauth-client-id

  1. On the credentials screen, choose “Web Application” for the “Application Type” and http://localhost:8080 under Authorized redirect URIs and Authorized JavaScript origins.

If you have a live web server running PHP, you can put the site address for the redirect URI but for this application, we will only use a local server running on port 8080. You only need to specify the port if your web service is running on a port than 80 (standard).

google-oauth-credentials

Google will show you the Client ID and Client Secret on the next screen. Dismiss the window and instead download the JSON file containing your OAuth client credentials. Move this JSON file in the root directory of your PHP application.

client-secret-json

In the next section, we’ll look at the actual PHP example that will connect our application to the user’s Gmail account via OAuth.

Amit Agarwal is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

Want to stay up to date?
Sign up for our email newsletter.

We will never send any spam emails. Promise 🫶🏻