How to dynamically display an application icon from a Google game

I am developing an application that shows a list of applications, and I want to get the icon of these applications from the Google play store to show it on the list, so if there is any way to do this, please tell me.

+4
source share
3 answers

I had to solve this problem myself recently when updating my portfolio, so I even have a code for you :) What I did was in php, but I'm not sure what you want to use. First, I checked the source of the page with my application using the developer tools β†’ developer-> (on chrome). Then, using this, I could cross the DOM to find something that I could use to identify the application icon. I found this: screenshot

that it showed that the application icon was stored inside a div with the class "doc-banner-icon" - I could not find this class anywhere, so I take for granted that this is the only div with this class. Then in my php code, I used simpledomparser to load the url, find the icon and spit out its url, for example:

<?php include('simple_html_dom.php'); $html = file_get_html("https://play.google.com/store/apps/details?id=com.smithyproductions.swissarmycarrot"); //put your app id here $bannerImage = $html->find('.doc-banner-icon'); //the class we found before $img = $bannerImage[0]->find('img'); //find the img tag inside the div $imgUrl = $img[0]->src; //get its src url $arr = array(); //in my own example I filled this array with other things like the title an screenshots $arr['imgUrl'] = $imgUrl; echo json_encode($arr); //output it in an easy to read format ?> 

leads to something like {'imgUrl', ' https://lh6.ggpht.com/1WMU4E3lnbjz5yxLHxsPrJAJPw3uYZ8LXk3QkD1EKOxwOcHu0W9QyGlpM5AfrKYEVzzi=w124 '}

The only thing you need to remember about this approach: Google can change the way everyone is presented and presented at any time, so get ready to update your application when that happens :)

+3
source

I changed the roarster code to work with the new play store webpage, and I simplified it:

 <?php include('simple_html_dom.php'); $play_link = $_GET['playlink']; //Play store link $html = file_get_html($play_link); //put your app id here $bannerImage = $html->find('div.cover-container'); //the class we found before $img = $bannerImage[0]->find('img'); //find the img tag inside the div $imgUrl = $img[0]->src; //get its src url $arr = array(); //in my own example I filled this array with other things like the title an screenshots $arr['imgUrl'] = $imgUrl; echo json_encode($arr); //output it in an easy to read format ?> 

Now you download, for example: yourwebpage.com/script.php?playlink=https://play.google.com/store/apps/details?id=com.igg.android.im

and you will get the result;)

+1
source

The problem is that Google is constantly changing the structure of the page, so I could not find any resource on how to officially handle this, as in the Apple Store.

Anyway, below is the php code I'm using for today (June 2019)

PS: in my code, when I manage to get the URL of the icon, I cache it in my database so that I no longer have to look for it in the Google Play store.

  try{ $lookupData = @file_get_contents('https://play.google.com/store/apps/details?id=com.google.android.gm&hl=en'); // Not valid any more $pregString = '/<meta itemprop="image" content="(.*?)"\/>/'; //June 2019 $pregString = '/<img src="(.*?)" srcset=".*" class=".*" aria-hidden="true" alt="Cover art" itemprop="image">/'; preg_match($pregString, $lookupData, $output); } catch (\Throwable $e) { $error = $e->getMessage(); if (strpos($error, '404 Not Found') === false) { //unknown error }else{ //Package not found, use default icon or something } } if(isset($output[1])){ //Store $output[1]; }else{ //icon not found, use default icon or something } 
0
source

All Articles