Google Play Store API
Introduction
In this entry you will learn a little more about the Google Play Store API, how it works and for what purpose. With this API you can make queries about how to get a list of apps in a certain category, get the details of a particular application or be able to read its privacy policy (if any). These are only a small part of all the functions that can be performed with this API and this is what we are going to see next.
Before starting, there are certain requirements to be considered. Firstly, you need a Google account (example@gmail.com) and secondly, once you have a Google account, you need to know two parameters associated to that account: the deviceID and the authToken. These parameters are necessary when performing authentication, but this will be explained later.
To make requests to an API, two things must always be taken into account, the HTTP header and the parameters. The HTTP header allows you to send specific additional information along with the request or response. They can be grouped according to their contexts (general, query, response and entity), according to their behaviour (end-to-end and pass-through) and according to their use (authentication, caching, client indications, conditionals, connection management…). For the usage of this API the HTTP headers to be used are the following:
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"User-Agent": "Android-Finsky",
"Accept-Language": "en-GB",
"X-DFE-Encode-Targets": "CAEScFfqlIEG6gUYogFWrAISK1WDAg+hAZoCDgIU1gYEOIACFkLMAeQBnASLATlASUuyAyqCAjY5igOMBQzfA/IClwFbApUC4ANbtgKVAS7OAX8YswHFBhgDwAOPAmGEBt4OfKkB5weSB5AFASkiN68akgMaxAMSAQEBA9kBO7UBFE1KVwIDBGs3go6BBgEBAgMECQgJAQIEAQMEAQMBBQEBBAUEFQYCBgUEAwMBDwIBAgOrARwBEwMEAg0mrwESfTEcAQEKG4EBMxghChMBDwYGASI3hAEODEwXCVh/EREZA4sBYwEdFAgIIwkQcGQRDzQ2fTC2AjfVAQIBAYoBGRg2FhYFBwEqNzACJShzFFblAo0CFxpFNBzaAd0DHjIRI4sBJZcBPdwBCQGhAUd2A7kBLBVPngEECHl0UEUMtQETigHMAgUFCc0BBUUlTywdHDgBiAJ+vgKhAU0uAcYCAWQ/5ALUAw1UwQHUBpIBCdQDhgL4AY4CBQICjARbGFBGWzA1CAEMOQH+BRAOCAZywAIDyQZ2MgM3BxsoAgUEBwcHFia3AgcGTBwHBYwBAlcBggFxSGgIrAEEBw4QEqUCASsWadsHCgUCBQMD7QICA3tXCUw7ugJZAwGyAUwpIwM5AwkDBQMJA5sBCw8BNxBVVBwVKhebARkBAwsQEAgEAhESAgQJEBCZATMdzgEBBwG8AQQYKSMUkAEDAwY/CTs4/wEaAUt1AwEDAQUBAgIEAwYEDx1dB2wGeBFgTQ",
"X-DFE-Device-Id": "****************",
"Authorization": "GoogleLogin auth=****************”,
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
The X-DEF-Device-Id and Authorization fields correspond to the deviceID and authToken mentioned above.
The parameters needed to complete the request are different for each of the actions, so they are explained within the details of each of them.
Overview
This section briefly shows the different services offered by the Google Play Store API, including the parameters to be included in each of the requests and their meaning.
Search
Search a set of applications in Google Play Store related to the given word.
method = GET
url = "https://android.clients.google.com/fdfe/search?c=3&q=gmail"
params = {
'c': 3, (Categories of applications)**
'q': 'gmail' (Given Word)
}
**In this entry we focus on the search and download of applications, but the API has more options (c=1 book categories, c=2 music categories and c=4 movie categories)
Browse
Browse the categories in Google Play Store.
method = GET
url = "https://android.clients.google.com/fdfe/browse?c=3&cat=ART_AND_DESIG&ctr=apps_topselling_free"**
params = {
'c': 3, (Categories of applications)
'cat': 'ART_AND_DESIG', (Category)
'ctr': 'apps_topselling_free' (Subcategory)
}
**If neither cat nor ctr are specified, return a list of categories
List
List a set of applications from Google Play Store given a category and a subcategory.
method = GET
url = "https://android.clients.google.com/fdfe/list?c=3&cat=ART_AND_DESIG&ctr=apps_topselling_fre&n=5"**
params = {
'c': 3, (Categories of applications)
'cat': 'ART_AND_DESIG', (Category)
'ctr': 'apps_topselling_free', (Subcategory)
'n': 5, (Max number of reviews to return)
'o': 0 (Offset: Used to take result starting from an index)
}
**If ctr is none, returns a list of valid subcategories
Details
Show the details of the given application.
method = GET
url = "https://android.clients.google.com/fdfe/details?doc=com.google.android.gm"
params = {
'doc': 'com.google.android.gm' (Package name: app unique ID)
}
Purchase
Download an app and return its raw data (APK file). Free apps need to be “purchased” first, in order to retrieve the download cookie.
method = POST
url = "https://android.clients.google.com/fdfe/purchase?ot=0&doc=com.google.android.gm&vc=0"
params = {
'ot': 0, (Offer type: different type of downloads)
'doc': 'com.google.android.gm', (Package name: app unique ID)
'vc': 0 (Version code)
}
Common errors
Some errors may occur while using the API. The most frequent ones are: error in the request or failure in the authentication. For the former, check each request carefully and confirm when writing a parameter whether it exists or not. If what fails is the authentication with google, there are several solutions depending on the failure. The credentials may have expired, so it would be sufficient to update them and they would work correctly. As a security measure, Google may ask you to perform this additional step when logging in to a new device or application. All you need to do is be logged in with the account you are using and click on this link: https://accounts.google.com/b/0/DisplayUnlockCaptcha. Finally, it is possible that your credentials are wrong and would have to be corrected for proper operation.
Conclusion
With all this, it is possible to search for and download a large number of applications as long as it is used correctly. As an example, there is a repository on github where you can see all the code of the Google Play Store API and also explains in detail an example of use with python as programming language. These are not all the functions that the API can perform, they are the most common though.
The link to the repository is: https://github.com/io-reyes/googleplay-api
Google Play Store API por bbalmori está licenciado bajo una Licencia Creative Commons Atribución-NoComercial-SinDerivar 4.0 Internacional.