Modern mobile phones are replacing many different devices and services. And the bigger part of their capabilities is hidden in the applications as developers are looking for the easiest and most secure ways of interacting with users. These factors have justified the creation of unique application storage: Google Play for Android and App Store for iOS. So today we will explore how to deal with application search, primary analysis, and much more.
How to get access to Google Play Store / App Store API
1. Sign up for a Free Account on RapidAPI
Because we don’t want to deal with parsing and hands-on apps search, we can just use APIs. And RapidAPI is a perfect place for this task. First of all, you will need to create an account there.
2. Navigate to the App Stores API
There are various options for Mobile Apps Storage processing, but we will work with the App Stores API. The reasons include:
- simplicity – only 4 endpoints;
- cross-platform – it supports both Google Play and iOS;
- comprehensiveness – we can get full info about apps, reviews, and ratings.
3. Subscribe to the API
Usage quota is the last, but not the least, advantage. The point is, different applications may have different interaction loads. Luckily, we have a free option in pricing:
According to this table, we can make a thousand requests monthly without any costs! So, choose this plan, subscribe, and we can move on.
How to Get & Download Google Play Store Data
Now we can investigate the chosen API. Let’s visit the API page and test all accessible endpoints. There are two groups of possible requests:
1. search:
- autocomplete – pretty basic endpoint which returns possible keywords for the sent data;
- app search – an important endpoint for application searching and getting their ids;
2. application:
- app details – the main endpoint to use if we want to get a description of the application;
- user reviews – another way to get some reviews for the app.
As you can see, we can cover a bigger part of available data about any application in the store. We can also use these endpoints across different platforms. This process is controlled via the store parameter of the request. If you would like to work with Google Play, then paste “google”. App Store will be available with the “apple” value. We will use GPlay data at a later stage, so just keep that in mind.
How to work with Google Play Apps API Data
We can now start to process API data with our code. If you don’t have Python 3 on your machine, install it. This is the only requirement for the technical stack of this article.
We also need to install the required requests module to ensure the project works.
pip install requests
Create a test file (e.g., test.py) and paste the following code:
from requests import request url = "https://app-stores.p.rapidapi.com/details" querystring = {"language":"en","store":"google","id":"com.snapchat.android"} headers = { 'x-rapidapi-host': "app-stores.p.rapidapi.com", 'x-rapidapi-key': "<YOUR_API_KEY>" } response = request("GET", url, headers=headers, params=querystring) print(response.text)
This is how you work with endpoints on Python. All lines are copied from the hint on the RapidAPI page of the App Details endpoint. You can also find multiple ways to work with APIs in many programming languages there.
Now execute python test.py
and you should see an output similar to the following:
{ "id":"com.snapchat.android", "url":"https://play.google.com/store/apps/details?id=com.snapchat.android", "name":"Snapchat", "category":"Social" "contentRating":"Teen" "releaseNotes":"Bug fixes and improvements! 👻", "description":"Life's more fun when you live in the moment :) Happy Snapping! * * * Please note: Snapchatters can always capture or save your messages, such as by taking a screenshot or using a camera. Be mindful of what you Snap!", "icons":{ "small":"https://lh4.ggpht.com/vdK_CsMSsJoYvJpYgaj91fiJ1T8rnSHHbXL0Em378kQaaf_BGyvUek2aU9z2qbxJCAFV=w300", "medium":"https://lh4.ggpht.com/vdK_CsMSsJoYvJpYgaj91fiJ1T8rnSHHbXL0Em378kQaaf_BGyvUek2aU9z2qbxJCAFV=w500", "large":"https://lh4.ggpht.com/vdK_CsMSsJoYvJpYgaj91fiJ1T8rnSHHbXL0Em378kQaaf_BGyvUek2aU9z2qbxJCAFV=w1000" }, "developer":{ "id":"Snapchat+Inc", "name":"Snapchat Inc", "url":"https://play.google.com/store/apps/developer?id=Snapchat+Inc", "website":"https://www.google.com/url?q=http://www.snapchat.com&sa=D&usg=AFQjCNHyxRDW7Q-4Vwh7h41dzgK6DDeLmA", "email":"support@snapchat.com", }, "ratings":{ "average":3.9, "total":5870693, }, "price":{ "raw":0, "display":"Free", "currency":"USD", }, "updatedAt":"2016-03-10T00:00:00.000Z", "currentVersion":"Varies with device", "minimumOsVersion":"Varies with device", "appSize":"Varies with device", "screenshots":[ 0: "https://lh3.googleusercontent.com/79mULVDiulfxsXMDccUIuZ-PM3fkE8ghfJqYe4wkguHhWcXnWq3Mr2YAS_eV9l-Gzu8=h900", 1: "https://lh3.googleusercontent.com/wftil9eMaCHaJ0xNj04x_TDMIjB1i8dqI1vOjmU7QVI_WRgYF4N0vm7l55nQ7BcV3MKn=h900", 2: "https://lh3.googleusercontent.com/YVUwf-w3Jgal2O4tV762azMAt_RurZbk2lWLoeH8i88wir27IiPK1bNwsyuLqCbzCDCW=h900", 3: "https://lh3.googleusercontent.com/8i89FG8mZ1YCATOkVHp5T8uxhz_T4LQD1aDb74o7pImSG_cKc3tuVoypTK4nO7ALFmk=h900", 4: "https://lh3.googleusercontent.com/tanxrE-msW4sYEY7xnGxgVCENo6KBL4oC675yzHsblgIeAAd0XnAUQoo0pV0QpA-UA=h900", ] }
It was easy and quick! Now we can consider the useful utilization of this API.
How to create an application for a Google Play Store exploring
How about some web applications to improve the searching process? We can easily integrate Google Play Apps searcher directly into our visual form.
We will use Django web framework to develop a website where users can search for the apps they are interested in. If you want to follow us, please install it and set it up properly.
We assume that practical examples are more understandable for people. So, create a new Django project like this:
django-admin startproject appstore
Next, go to the App Store folder and start the new application:
python manage.py startapp core
Perform the Django migrations needed to the correct workings of the application:
python manage.py migrate
Add the ‘core.apps.CoreConfig’ element to the INSTALLED_APPS variable in the settings.py file.
Copy and paste the following pieces of code in the corresponding files:
appstore/urls.py:
from django.contrib import admin from django.urls import include, path urlpatterns = [ path('', include('core.urls')), path('admin/', admin.site.urls), ]
core/urls.py
from django.urls import path from . import views app_name = 'core' urlpatterns = [ path('', views.IndexView.as_view(), name='index'), path('apps/', views.AppsListView.as_view(), name='apps_list'), path('apps/<app_id>/', views.AppDetailsView.as_view(), name='app_details'), ]
Both urls.py files are responsible for routing on the website. Here we will have three pages: the main page with the search bar, the page with the found apps list, and the page with the particular app’s details.
core/templates/core/index.html
<form method="post"> {% csrf_token %} {{ form }} <input type="submit" value="Search"> </form>
core/templates/core/apps_list.html
{% if apps_data %} <ul> {% for app in apps_data %} <li> <img src="{{ app.icons.small }}" width="45" height="45"> <h5>Name: {{ app.name }}</h5> <p>Average rating: {{ app.ratings.average }}</p> <p>Total: {{ app.ratings.total }}</p> <a href="{% url 'core:app_details' app_id=app.id %}">Details</a> <p></p> </li> {% endfor %} </ul> {% else %} <p>No apps are available.</p> {% endif %}
core/templates/core/app_details.html
<h1>{{ app_details.name }}</h1> <img src="{{ app_details.icons.small }}" width="90" height="90"> <p><b>Rating average:</b> {{ app_details.ratings.average }}</p> <p><b>Rating total:</b> {{ app_details.ratings.total }}</p> <a href="{{ app_details.url }}"><b>Get the app</b></a> <p><b>About:</b></p> <p>{{ app_details.description }}</p> <a href="{% url 'core:index' %}"><b>Back to home page</b></a>
All HTML files are templates. The Django views (you can find them below) pass some data to templates, and templates are used to specify what should be rendered where on the page in the browser window.
core/forms.py
from django import forms class SearchAppForm(forms.Form): query = forms.CharField(label='What do you want to find:', max_length=100)
The forms.py file defines a class for the form. The form has just one field where users can enter the search query.
core/views.py
from django.shortcuts import render, redirect from django.views.generic.base import View import json import requests from .forms import SearchAppForm class APIConnector: def __init__(self): self.headers = { 'x-rapidapi-host': "app-stores.p.rapidapi.com", 'x-rapidapi-key': "<YOUR_RAPIDAPI_KEY>" } self.url_basic = "https://app-stores.p.rapidapi.com/" self.querystring = {"language": "en", "store": "google"} class IndexView(APIConnector, View): def get(self, request, *args, **kwargs): form = SearchAppForm() return render(request, 'core/index.html', {'form': form}) def post(self, request, *args, **kwargs): form = SearchAppForm(request.POST) if form.is_valid(): url = self.url_basic + 'search' querystring = dict({'term': form.cleaned_data['query']}, **self.querystring) response = requests.request("GET", url, headers=self.headers, params=querystring) apps_response_data = json.loads(response.text) request.session['apps_data'] = apps_response_data return redirect('core:apps_list') else: return render(request, 'core/index.html', {'form': form}) class AppsListView(View): def get(self, request, *args, **kwargs): apps_response_data = request.session['apps_data'] return render(request, 'core/apps_list.html', {'apps_data': apps_response_data}) class AppDetailsView(APIConnector, View): def get(self, request, app_id): url = self.url_basic + 'details' querystring = dict({'id': app_id}, **self.querystring) response = requests.request("GET", url, headers=self.headers, params=querystring) app_details_response_data = json.loads(response.text) return render(request, 'core/app_details.html', {'app_details': app_details_response_data})
The views.py file is where all the logic is located. The APIConnector class is the mixin for its inheritors. It stores the common data required to connect to the App Store’s API: host, credentials, basic url, and query string.
When the POST request goes to IndexView, the app takes the query entered by the user and sends it to the API. Then the view parses the response and saves it to the session variable and then redirects to the page with the apps list.
The AppsListView renders the page with the apps list (fetched from the session variable). The AppDetailsView makes the request to the App Details endpoint of the API and renders the data from the API response.
To start the development server and test the application, run the following command:
python manage.py runserver
The application requires minimal frontend input. On the home page, you can see the form with the search field. Let’s type, for example, “Python” as a search query:
After we hit the Search button, the site redirects us to the /apps/ page, where we can see the results of the search:
Finally, if we follow the Details link near one of the applications, our website will render the page with that app’s details:
As you can see, our website is working. Now it is very easy to search for mobile apps.
Conclusion
In this tutorial, we explored the App Store’s API on the RapidAPI platform. We showed you a basic example of how the API can be used inside the Django web application. If you need to implement mobile apps (from Google Play or App Store) search on your website or application, this API could be very useful. It allows you to search for apps (with the autocomplete feature) and explore reviews and details of particular apps.
Leave a Reply