How to get app market version information from google play store?

后端 未结 15 1571
孤独总比滥情好
孤独总比滥情好 2020-11-29 00:33

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

15条回答
  •  攒了一身酷
    2020-11-29 01:09

    Old version (NO LONGER WORKS)

    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()); });

    Current solution

    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;
                    }
                }
            }
        }
    }
    

提交回复
热议问题