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.
- Go to
console.developers.google.comand create a new project.
- Give your project a name.
- Go to Library, search for the Google APIs that you wish to use in your application and enable them one by one.
- Go to Credentials -> Create Credentials -> Oauth Client Id. We’ll discuss service accounts in a later chapter.
- On the credentials screen, choose “Web Application” for the “Application Type” and
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 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.
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.
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.
Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory