Tech Hub

Google Play Developer API: How to Create a Service Account

May 4, 2022

Posted by: Rahul Upadhyay

Google Play Developer API: How to Create a Service Account

Why am I reading this?

  • Mobile applications are surrounded by so many modules in addition to that, the IN-APP Purchase and Subscriptions play a good amount of role, where you as an owner of the app, can generate revenue by selling consumable and non-consumable goods such as Coins for Games, Subscription plans for your app many things.  
  • Now, as you are selling some goods on your app, there must be a way to validate that purchase or get the details. But obviously, you can do it from the app itself as Google does provide SDK for the same. (SDK – Software Development Kit). But, we are living in a world where Android and iOS exist and are in a very competitive market!  
  • Google Play Developer API gives us the power to check the user’s transaction from the RESTful APIs which leads you to read this blog.  
  • With the RESTful API, we can do this call from the BACKEND and leave the app standalone and do other stuff 

Offering

Google Play Developer API lets you manage the 2 main components in your project 

  1. The Publishing API lets you upload and publish apps, and perform other publishing-related tasks.
  2. The Subscription and IN-APP Purchase API lets you manage in-app purchases and subscriptions. [We are going to explore these APIs]

Objective 

To verify the Google In-App Purchase and Subscriptions (IAP) 

Requirements 
  1. Google Play Developer Console Access
  2. Google Cloud Console Access
Note: To start making API calls, you will set up and manage the Google Play Developer API directly from the Google Play Console. The API can be managed by the Google Play Developer Account owner.  

Tip: If you already have an existing project over Google Cloud Console then it should be using the same google account you used for the Google Play Console. If you have a different account setup then there are specific steps and roles with which we can achieve this. 

 Here are the main steps we are focusing on:  

  1. Set up a new or existing Google Clod Project
  2. User, a service account to access the Google Play Developer API
  3. Access the RESTful APIs for analyzing the app

Let's Start

Linking your account and project

Before you can access the Google Play Developer API, you must link your Google Play Developer Account to a Google Cloud Project. In most cases, we recommend that you create a new Google Cloud Project dedicated to your Google Play Developer Account, but you can link an existing project. Keep in mind that each Google Play Developer Account can only be linked to a single Google Cloud Project. If you have multiple apps in the same Google Play Developer Account, they all must share the same Google Cloud Project. 

Access Google Play Developer Console
  1. Log In to Google Play Developer Console Play Console (google.com)
  2. Select your account  
  3. On the side navigation menu, select Setup>AP Access 
     
  4. Agree with API terms of service (Just follow on-screen instructions if any).   
  5. Once done, you will be seeing options to link your existing project or create a new project.
  6. If you already have a Google Cloud Project then you can Link that project or you can create a new project.
    1. Link existing project
      1. Select the existing project by clicking on Choose Project dropdown menu If your project isn’t listed, verify that your Google Play Console account is with the role OWNER and Google Play Developer API is enabled for the project. If not then you can do it quickly by following, how to do it? 
        1. Select the project and click on the SAVE button  
        2. You will be seeing a page like this. We need to work on the Service Accounts section. If you already have a service account then you will be seeing it listed. If not then we will create a new service account.  
    2. Create New Project
      1. Select the option Create New Project and click the SAVE button 
        1. A new project will be created and you can see that project below
        2. We can edit the project name later from the Google Developer Console. 

Configure Service Accounts

Most common secure software service which will access the API.  

Service accounts must be used in a secure environment, such as your server. The service account credentials need to be securely managed so they are not revealed to anyone that is not authorized to use the API. 

Once we have project linked or created, our main goal is to Create new Service Account or give an access to already created service account.  

  1. Create a new service account
    1. Read the instruction once you click this button, "CREATE NEW SERVICE ACCOUNT"
    2. Click on the option #1, Go to the Google Cloud Platform and open that URL in the new tab 
    3. Now, you are on the Google Console
    4. Click on the CREATE SERVICE ACCOUNT and follow the next step
       
    5. Name your service account and provide the description. No need to alter the 2nd field
    6. Click on CREATE AND CONTINUE. Here we need to defile ROLE to this SERVICE ACCOUNT
    7. Search for Service Account Admin and click on the role
    8. Once selected, click on CONTINUE
    9. We are not doing anything in the 3rd step, just click DONE
    10. Your service account has been created and listed on the same page
    11. Select the account and switch to the "KEYS" tab. We are going to add a new key to this service account.   
    12. Click on ADD KEY and select CREATE NEW KEY  
    13. Select the Key type as JSON and click on the CREATE
    14. The key will be created and will ask you to download it. Save the file as it is. We will need this for the development and ask you to provide that. Close this dialogue box.
    15. You can see the created key listed on the page
  2. Grant access to the Service Account
    1. Now, go back to the PLAY CONSOLE PAGE, #7.a from this document. And click on DONE. You will see the newly created service account under the SERVICE ACCOUNTS section
    2. Click on the GRANT ACCESS (from step 8) and you will be seeing the following screen
    3. Check these 2 boxes, click on the INVITE USER
       
      select SEND INVITATION on the confirmation box 
    4. Once done, you will see this screen with the new service account added as a User. If not then please Enable Google Play Developer API

Enable Google Play Developer API

Need to enable Google Play Developer API from the Google Cloud Console. Open the Google Cloud Console which you already have opened in the step Create a new service account #c

  1. Click on the Hamburger menu, select APIs & Services > Library
  2. Search for "Google Play Android Developer API" and click the searched result
     
  3. Enable this API. Once enabled
  4. Once done you will be able to see the Service Account listed in step Grant access to the Service Account #d

Hope you have fun reading this blog and heading towards getting a coffee. Happy setting up. Let me know your thoughts, and questions in the comments section below. 

Thank you. 

References:

Share this


Back