Lets just pick one of the package name say "com.facebook.katana", and lets google it.
the first result (if its a valid android app) would be the play url like - https://play.google.com/store/apps/details?id=com.facebook.katana, lets hit this url and look at the source of it.
a span like this has what we need -
<span itemprop="genre">Social</span>
Now lets write a dirty index game in php to get the genre or category of our package, i hope y'all find it easy to understand, coz it ain't rocket science
the code is available here https://gist.github.com/brijrajsingh/6915711
and is given below as well.
Note - I would also suggest that once you have got a category for a package name you better store it in some db or memcache, so you don't need to hit it again and again for diff packages, also the code might stop running if you bombard the google servers, so go easy on it.
<?php
class PackageCategory
{
protected static $playurl = 'https://play.google.com/store/apps/details?id=';
public function PackageCategory($packageName) {
$this->packageName = $packageName;
}
public function getPackageCategory()
{
$result = $this->makeRequest(self::$playurl.$this->packageName);
//starting index of category tag
$indexstart = strpos($result,"<span itemprop=\"genre\">");
//ending index of category tag
$indexend = strpos($result,"</span>",$indexstart);
$category = substr($result,$indexstart+23,$indexend - ($indexstart+23));
echo $category;
}
//curl to the play store
/**
* Makes request to AWIS
* @param String $url URL to make request to
* @return String Result of request
*/
protected function makeRequest($url) {
//echo "
Making request to:
$url
";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
if (count($argv) < 2) {
echo "Usage: $argv[0] PackageName
";
exit(-1);
}
else {
$packageName = $argv[1];
}
$packageCategory = new PackageCategory($packageName);
$packageCategory->getPackageCategory();
?>