Setting up Google Gmail REST API can be a bit complicated for most users, and it is important to follow the instructions on how to get the proper access keys and authorize the plugin to access the Gmail API. Unfortunately, Google likes to make changes to their interface very often, and it can happen that some screens don’t look exactly like the images here, so make sure you understand how the process works even if the images don’t match exactly.
Gmail API access can’t be set on the localhost or local development domains, it has to be a live domain that can be accessed over the Internet. For this purpose, we are using redirected local domain via Ngrok.io service.
Step 1: Enable Gmail API
By default, for all Google accounts, most API’s are disabled by default, including Gmail API, so you need to enable it. Visit this URL (you need to log in with your Google account): https://console.developers.google.com/. If you are visiting this console for the first time, you will need to accept Terms and Conditions to continue.
Click on the Library button on the left side, and in the field for search, type Gmail. Gmail result will be displayed, click on it, and then click button Enable. If the API is already enabled, this button will be replaced with button Manage.
Step 2: Create a Project
After you enable this, Console will return to the main screen, where you will get the option to create a project. You can give the project any name you want, and depending on the type of Google account you have, there can be additional options to select an organization. Select the new project from the dropdown on the top of the page.
Step 3: Create Credentials
Open the Credentials page (URL: https://console.developers.google.com/apis/credentials) and it should look like this if you don’t have any other credentials already.
Open Create Credentials blue button, and select the last option from the list: Help me choose. You need to answer a few questions.
- Which API are you using?
Select Gmail API from the list.
- Where will you be calling the API from?
Select Web Server from the list.
- What data will you be accessing?
Select User Data.
Consent Screen Information
Now, click button What credentials do I need? and the popup will appear to set up the Consent screen. On the consent screen, set application type to Internal, and add anything like the name of the application, the logo is not required. Support email should display your Gmail account there.
Click save, and you will be returned to the Credentials screen, so you need to go through Step 3 again. But, instead of the Consent Screen question, you will need to set up the OAuth2 client. Set any name (or leave default). Now, you need to enter two URL’s plugin provides on the Gmail settings panel:
Enter these URL’s into the Client information, and it will look like this:
Click Create OAuth Client ID button, and after it finishes, click Done. You will be transported back to the Credentials panel.
Step 4: Get Access keys
Now, click the edit link in this list (small pen like icon at the end). A new page will open, with access keys on the top:
Now, copy these keys into plugin settings, and click Save Settings.
Step 5: Authorize plugin to use Gmail API
After you do that, the plugin settings page will include an additional block with authorization option.
Now, click on the Authorize this website button, and the page will open to classic Google authorization page where you need to select your account (must be the account you used to create the API credentials), and authorize it (Allow) for use on your website. Once you do that, you will land back to the plugin settings page, and if all was OK, the authorization will be saved and you will now see the different message and different button to remove the authorization.