I'm developing an application that show a list of applications, and I want to get the Icon of this applications from the Google play store to show it in the list, so if there are any way to do that please tell me.
I had to tackle this problem myself recently in updating my portfolio website, so i even have some 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 app on it using view->developer->developer tools (on chrome). Then using that i could traverse the DOM looking for something i could use to identify the app icon. I found this:
what this showed is that the app icon was held inside a div with class "doc-banner-icon" - I couldn't find this class anywhere else, so i take it for granted that it is the only div with that class. Then in my php code i used simpledomparser to load the url, locate the icon and spit out it's url, like so:
<?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
?>
resulting in something like
{'imgUrl','https://lh6.ggpht.com/1WMU4E3lnbjz5yxLHxsPrJAJPw3uYZ8LXk3QkD1EKOxwOcHu0W9QyGlpM5AfrKYEVzzi=w124'}
Just one thing to bear in mind about this approach: Google could change the way everything is presented and laid out at any time so prepare to update your app when this happens :)
'div.cover-container img.cover-image'
. Good idea although completely unreliable. –
Eh I modified the code by roarster to get working with new web page of the play store 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 load for example: yourwebpage.com/script.php?playlink=https://play.google.com/store/apps/details?id=com.igg.android.im
and you get the result ;)
The problem Google keep changing the structure of the page, so far I couldn't find any resource in how to handle this in an official way similar to Apple Store.
Anyway, below is the php code that I use as of today (June 2019)
PS: in my code, once I manage to get the icon URL I cache it in my database so I don't have to look it up again in 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
}
© 2022 - 2024 — McMap. All rights reserved.