从Google Play获取应用程序下载次数是可能的吗?

22

我正在尝试获取我上传到 Google Play 的应用程序的下载次数。

我正在寻找一个API(或类似的东西),可以通过用户的身份验证为我检索下载次数。我不想使用第三方应用程序(如AppAnnie)。

如果可以用PHP实现,那就太好了。我发现有一个库,我认为它是从Google应用程序中获取数据最接近的API。

Google APIs Client Library for PHP

但我找不到任何提到Google Play应用程序的信息。

有没有办法使用身份验证密钥获取特定应用程序的下载次数?

先谢谢你!

7个回答

8
使用google-play-scraper库可以获取如下的应用信息: 示例:
$app = $scraper->getApp('com.mojang.minecraftpe');

结果:

array (
  'id' => 'com.mojang.minecraftpe',
  'url' => 'https://play.google.com/store/apps/details?id=com.mojang.minecraftpe',
  'image' => 'https://lh3.googleusercontent.com/30koN0eGl-LHqvUZrCj9HT4qVPQdvN508p2wuhaWUnqKeCp6nrs9QW8v6IVGvGNauA=w300',
  'title' => 'Minecraft: Pocket Edition',
  'author' => 'Mojang',
  'author_link' => 'https://play.google.com/store/apps/developer?id=Mojang',
  'categories' => array (
    'Arcade',
    'Creativity',
  ),
  'price' => '$6.99',
  'screenshots' => array (
    'https://lh3.googleusercontent.com/VkLE0e0EDuRID6jdTE97cC8BomcDReJtZOem9Jlb14jw9O7ytAGvE-2pLqvoSJ7w3IdK=h310',
    'https://lh3.googleusercontent.com/28b1vxJQe916wOaSVB4CmcnDujk8M2SNaCwqtQ4cUS0wYKYn9kCYeqxX0uyI2X-nQv0=h310',
    // [...]
  ),
  'description' => 'Our latest free update includes the Nether and all its inhabitants[...]',
  'description_html' => 'Our latest free update includes the Nether and all its inhabitants[...]',
  'rating' => 4.4726405143737793,
  'votes' => 1136962,
  'last_updated' => 'October 22, 2015',
  'size' => 'Varies with device',
  'downloads' => '10,000,000 - 50,000,000',
  'version' => 'Varies with device',
  'supported_os' => 'Varies with device',
  'content_rating' => 'Everyone 10+',
  'whatsnew' => 'Build, explore and survive on the go with Minecraft: Pocket Edition[...]',
  'video_link' => 'https://www.youtube.com/embed/D2Z9oKTzzrM?ps=play&vq=large&rel=0&autohide=1&showinfo=0&autoplay=1',
  'video_image' => 'https://i.ytimg.com/vi/D2Z9oKTzzrM/hqdefault.jpg',
)

编辑: 可以轻松地获取以下的下载次数:

echo $app['downloads']; // Outputs: '10,000,000 - 50,000,000'

或者如果您想要左侧的值:

$matches = null;
$returnValue = preg_match('/.*(?= -)/', '10,000,000 - 50,000,000', $matches);
echo $matches[0]; // Outputs: '10,000,000'

如果您想获取正确的值:

$matches = null;
$returnValue = preg_match('/(?<=- ).*/', '10,000,000 - 50,000,000', $matches);
echo $matches[0]; // Outputs: '50,000,000'

然后可以轻松使用以下代码将其转换为整数:
$count = null;
$returnValue = (int)preg_replace('/,/', '', $matches[0], -1, $count);
echo $returnValue; // Outputs: 10000000 or 50000000

我想在Play商店上发布一个应用程序,其中我想使用这个。这是否违反了政策或者谷歌会拒绝我的应用程序? - Noobdeveloper
1
@Noobdeveloper 我不确定这是否违反了他们的政策,顺便说一下,从网站上进行数据抓取大多会违反他们的条款,但被抓取的数据已经公开可供浏览,所以我认为这方面没有任何问题,也许其他专家可以提供更多细节,我认为这主要取决于你对被抓取的数据做什么,而不是抓取本身。 - Hasan Bayat

5

3
你需要对其进行网页抓取。一般来说,当网站(例如:Google Play)没有提供API使客户端能够访问所需的数据时,网页抓取是收集信息的最佳方法之一。
几乎所有在网页上可见的信息都可以被抓取。如今,随着网络爬虫的巨大改进,不仅可以从目标网站获取数据,而且“像用户一样爬行”,“通过表单向网站发布信息”,“以用户身份登录”等已成为任何网络爬虫的例行工作。

有很强大的网络爬虫工具可用,例如Scrapy(可能是最负盛名的Python编写的工具),几乎适用于所有语言。据我所知,PHP中最好的网络爬虫工具是Goutte,由传奇人物@fabpotFriendsOfPHP编写而成。

从数据提取的角度来看,Goutte支持“CSS选择器”和XPath(因为它使用Symfony's DOM Crawler作为爬行引擎)。因此,您可以按照自己的方式爬取文档,从网页的任何隐藏角落提取每一个信息片段!

使用Goutte可以进行大量的网络爬取,但只需举一个小例子,即可轻松抓取普通应用程序页面中的“安装数量”:

use Goutte\Client;

$Client = new Client();

/**
* @var \Symfony\Component\DomCrawler\Crawler 
*/
$Crawler = $Client->request('GET', "https://play.google.com/store/apps/details?id=com.somago.brainoperator&hl=en");

$numberOfInstalls = $Crawler->filter('div.details-section-contents div.meta-info')->eq(1)->filter('div.content')->eq(0)->text();

echo $numberOfInstalls;

它将简单地打印 Brain Operator游戏的“下载次数”。

2

在Python中,您可以使用以下方法。

from google_play_scraper import app #if not installed google_play_scraper then install by **pip install google-play-scraper**

playstore = app('test.example.com');

print(playstore):

1

但是我需要一个类似于PHP的东西来在网页上显示。 - Francisco Romero

1

查看这个库42 matters,可以获得下载次数、评分等信息。


0

使用AppID,您可以从GooglePlay API获取它。

或者,如果应用程序是您自己的,则可以从Google Cloud(reference)导出统计数据。


由于OP正在寻求PHP,这个可能是你要找的。 - Leith

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接