How can I get the application version information from google play store for prompting the user for force/recommended an update of the application when play store applicatio
Here is jQuery version to get the version number if anyone else needs it.
$.get("https://play.google.com/store/apps/details?id=" + packageName + "&hl=en", function(data){
console.log($('').html(data).contents().find('div[itemprop="softwareVersion"]').text().trim());
});
Using PHP backend. This has been working for a year now. It seems Google does not change their DOM that often.
public function getAndroidVersion(string $storeUrl): string
{
$dom = new DOMDocument();
$dom->loadHTML(file_get_contents($storeUrl));
libxml_use_internal_errors(false);
$elements = $dom->getElementsByTagName('span');
$depth = 0;
foreach ($elements as $element) {
foreach ($element->attributes as $attr) {
if ($attr->nodeName === 'class' && $attr->nodeValue === 'htlgb') {
$depth++;
if ($depth === 7) {
return preg_replace('/[^0-9.]/', '', $element->nodeValue);
break 2;
}
}
}
}
}