是否存在可从Google Play Store查询应用最新版本的API?
适配新版Google Play Store的版本查询方案
1. 官方Google Play Developer API(最稳定)
这是官方合规的方案,需要配置开发者账号权限:
- 登录Google Play Console,进入「设置」>「API访问」,创建服务账号并下载JSON密钥文件
- 将密钥内容存入GitHub仓库的Secrets,命名为
PLAY_SERVICE_ACCOUNT_KEY - 在GitHub Actions工作流中添加以下步骤获取版本:
- name: 获取Play Store生产版本 id: get_play_version uses: actions/github-script@v6 with: script: | const { google } = require('googleapis'); const auth = new google.auth.GoogleAuth({ credentials: JSON.parse(process.env.PLAY_SERVICE_ACCOUNT_KEY), scopes: ['https://www.googleapis.com/auth/androidpublisher'] }); const androidpublisher = google.androidpublisher({ version: 'v3', auth }); // 获取生产渠道的版本信息 const trackRes = await androidpublisher.edits.tracks.get({ packageName: 'com.your.app.package', editId: (await androidpublisher.edits.list({ packageName: 'com.your.app.package' })).data.edits[0].id, track: 'production' }); const latestVersionCode = trackRes.data.releases[0].versionCodes[0]; core.setOutput('play_version', latestVersionCode); env: PLAY_SERVICE_ACCOUNT_KEY: ${{ secrets.PLAY_SERVICE_ACCOUNT_KEY }} - 后续可通过
${{ steps.get_play_version.outputs.play_version }}拿到版本号,和目标版本对比触发流程
2. 爬虫方案(无开发者账号可用)
如果无法使用官方API,可通过爬虫适配新版Play页面,用Puppeteer在Actions中运行:
- name: 配置Node环境 uses: actions/setup-node@v4 with: node-version: '20' - name: 爬取Play Store版本号 id: scrape_play_version run: | npm install puppeteer node -e " const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({ headless: 'new' }); const page = await browser.newPage(); await page.goto('https://play.google.com/store/apps/details?id=com.your.app.package&hl=en'); // 适配新版页面的选择器,若页面更新需调整 const versionText = await page.$eval('.hAyfc .htlgb:nth-child(2) .IQ1z0d', el => el.textContent); console.log(`::set-output name=play_version::\${versionText}`); await browser.close(); })(); "
- 注意:Play页面结构可能变动,需定期检查选择器有效性
3. 社区封装的GitHub Actions工具
直接使用社区维护的工具,无需自己写逻辑:
- name: 获取Play Store版本 id: get_version uses: r0adkll/get-play-store-version@v1.0.3 with: packageName: com.your.app.package
- 该工具会自动适配最新Play页面,更新频率较高
内容的提问来源于stack exchange,提问作者ifeomaro
相关产品推荐
相关产品推荐

