This is unofficial service-wrapper of Google Play Developer API for retrieving Android app version that currently located on Google Play Store in simple JSON (REST) response.
Just call GET request /?id={com.app.app}
and get last app version (Beta
versions not captured)
Request to Google Play Developer API takes about 3 second. That's why this service cached app version for 4 hour. So you will receive information from the delay up to 4 hours.
You have put your app on the Google Play Store. It has been installed by lots of customers. The users should check the auto-update check box in the Play Store app for each app they want to auto-update. However some users have unchecked it or not checked it in the first place.
So you may want to use some service to pragmatically check if there is an updated version of my app on the Play Store. If there is an updated version then the user could be directed to the Play Store.
Google Play does not provide any official APIs for retrieving metadata in simple way.
So I found several solution on stackoverflow. There are 2 types of them:
- Use some open web services like https://androidquery.appspot.com/api/market?app=org.ligi.fast or http://carreto.pt/tools/android-store-version/?package=org.ligi.fast
- Use own API with hardsaved app version on backend
- Use http://api.playstoreapi.com/v1.1/apps
- Get version value from your Google Play Store page. (http://stackoverflow.com/questions/25201349/programmatically-check-play-store-for-app-updates and http://stackoverflow.com/questions/7298106/how-to-allow-users-to-check-for-the-latest-app-version-from-inside-the-app and many others)
First services just wrapper for web page or hosted on google app engine which usually outage when daily free quota used up.
With Second solution you have to update hardcoded version number every release. For example we release a new version every week and forgot to update hardcoded version number saved on our backend.
Third. www.playstoreapi.com is not available anymore.
Fourth solution is pretty good. You have to get this value from your Google Play Store page.
<div class="content" itemprop="softwareVersion">1.2.5</div>
But you have to update the app when something in html is changed. And this method have another side effect. Google don't show app version number when you use several platforms (x86 and armeabi-v7a). For example https://play.google.com/store/apps/details?id=com.wipon.wipon page have not version number on it.
That's why I'd like to use Google Play Developer API and fake deploy mechanism to get apk's list. This method is the most stable in my opinion. It realised in this repo
pip install -r requirements.txt
Python 2.6 or 2.7 are fully supported. This requirement flew from google-api-python-client
Python 3.3+ is also now supported! However, this service has not yet been used as thoroughly with Python 3, so I'd recommend testing before deploying with Python 3 in production.
Configuration is simply copying the OAuth2 key to project folder.
- Go to the APIs Console and log in with your Google Play Developer Console account.
- Go to Settings → API access
- Turn the Google Play Android Developer API on if it's not
- Create or link Google Developer Project with Google Play Developer Console account
- Go to Service Accounts and Grant Access to this account
- Click Add user on window above
- Generate OAuth service account in Google Developer Console
- Create JSON (NOT p12) keyfile and Save as
key.json
in the project directory - That's it
More details on official docs https://developers.google.com/android-publisher/authorization
Start android_version_checker
python android_version_checker.py
sh ./start-stage.sh
Optionally you can use supervisor/staging_android_version_checker.conf
supervisor program config.
You can follow this link https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-16-04 or instruction below.
For example I use /var/www/android-version-checker as project folder.
$ sudo apt-get install virtualenv
$ cd /var/www/android-version-checker
$ virtualenv env
$ source env/bin/activate
$ sudo env/bin/pip install --upgrade pip
$ sudo env/bin/pip install gunicorn
$ sudo env/bin/pip install -r requirements.txt
$ env/bin/python2 android_version_checker.py
$ env/bin/gunicorn --bind 0.0.0.0:5005 wsgi:app
8. Create a systemd Unit File (don't forget modify path). Group must be www-data otherwise nginx can not access to sock file.
$ sudo nano /etc/systemd/system/android_version_checker.service
[Unit]
Description=Gunicorn instance to serve android_version_checker
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/android-version-checker
Environment="PATH=/var/www/android-version-checker/env/bin"
ExecStart=/var/www/android-version-checker/env/bin/gunicorn --workers 3 --bind unix:android_version_checker.sock -m 007 wsgi:app
[Install]
WantedBy=multi-user.target
$ deactivate
$ sudo systemctl start android_version_checker
$ sudo systemctl enable android_version_checker
$ sudo ufw allow 5005
server {
listen 5005;
server_name server_domain_or_IP;
access_log /var/log/nginx/android-version-checker.access.log;
error_log /var/log/nginx/android-verdion-checker.error.log;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/var/www/android-version-checker/android_version_checker.sock;
}
}
By default API runs on 5005
port.
Returns app version by package id
id
- Required field. Android Package identifiermask
- Optional field. Mask for version format. The following characters are recognized in the format parameter string: "H - Major, L- Minor, P-Patch, I-ignore". By default "HILPIII"
{
"last_version": "<version nubmer>"
}
Example of version number: 2.5.3
{
'error': 'Can`t load credentials. The key file is empty or corrupted. Contact your server administrator.'
}
Look at configuration. Maybe you haven't credential file.
{
'error': 'Can't find package <package id>'
}
Look at Google Play Developer Console. You may have an error on it.
{
'error': 'No one valid version for <package id> was found.'
}
This service support apk version like 2005304
or 100004
{
'error': 'The package name undefined. Example: com.android.sample'
}
Check your Google Play Developer Console. Do you upload apk file?
{
'error': 'The package name undefined. Example: com.android.sample'
}
id
- Required field.
{
'error': 'Can't get android version for some reason'
}
Something else happened. Maybe your server don't have stable internet connection.
All contributions are more than welcome.
Distributed under the MIT license