【问题标题】:How to programmatically get the version of an app on Huawei AppGallery?如何以编程方式获取华为应用市场上的应用版本?
【发布时间】:2020-07-21 11:47:51
【问题描述】:

我知道如何为 Google Play Store (answer here) 完成此操作,但我没有设法为 AppGallery 找到方法。 谢谢!

更新 #1

使用下面的答案,我通过以下步骤部分解决了这个问题:

  1. 创建一个具有管理员角色的 API 客户端,它也适用于应用管理员和操作。 (此处的文档:API Client
  2. 获取访问令牌。 (此处的文档:Obtaining a Token
  3. 获取应用信息。 (此处的文档:Querying App Information

Querying App Information 的响应,有很多关于应用程序的信息,包括“versionNumber”,但对我来说,它不提供“versionNumber”(我需要的单个信息),因为这个参数是可选的。现在我又被卡住了,因为我不明白我需要改变什么才能收到这个。

如果有人知道我该如何解决这个问题,非常感谢您的帮助。

更新 #2

@shirley 的评论是正确的。 该问题已在其最新版本中得到修复,并已于本月发布。

【问题讨论】:

  • 我已经编辑了您的问题,以尝试更清楚地表明您正在通过代码寻找解决方案,如果您对我的更改不满意,请随时更改它:)

标签: android google-play huawei-mobile-services appgallery


【解决方案1】:

您可以调用查询应用信息接口(GET方式)查询应用详情:

public static void getAppInfo(String domain, String clientId, String token, String appId, String lang) {
     HttpGet get = new HttpGet(domain + "/publish/v2/app-info?appid=" + appId + "&lang=" + lang);
     get.setHeader("Authorization", "Bearer " + token);
     get.setHeader("client_id", clientId);
     try {
         CloseableHttpClient httpClient = HttpClients.createDefault();
         CloseableHttpResponse httpResponse = httpClient.execute(get);
         int statusCode = httpResponse.getStatusLine().getStatusCode();
         if (statusCode == HttpStatus.SC_OK) {
             BufferedReader br =
                     new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), Consts.UTF_8));
             String result = br.readLine();
             // Object returned by the app information query API, which can be received using the AppInfo object. For details, please refer to the API reference.
             JSONObject object = JSON.parseObject(result);
             System.out.println(object.get("ret"));
         }
     } catch (Exception e) {
     }
 }

这里提到了它们:Completing App InformationQuerying App Information

【讨论】:

  • 感谢您的回答。我创建了一个具有管理员角色的 API 客户端,并请求查询应用程序信息,但响应没有“版本号”。在文档中写到“versionNumber”是可选的,但我怎样才能让它显示在请求的响应中?
  • @Anna 你能留下你的appId吗?让我检查信息以查看问题。此外,在 AGC 中创建的应用程序的许多基本信息默认为空。 Completing App Information 描述了如何通过 Publishing API 完成应用信息。
  • app id 是 102606985。在文档中写到你可以更新多个信息(Updating Basic App Information),但不包括“versionName”参数。
  • @Anna 感谢您的联系。该问题已在其最新版本中得到修复,并将在 2020 年 8 月下旬发布。
  • HttpPost 和 HttpGet 已经被弃用了吧?
猜你喜欢
  • 2021-09-23
  • 2020-04-08
  • 2012-08-18
  • 2019-05-11
  • 1970-01-01
  • 2022-06-17
  • 2016-03-22
  • 2021-10-10
  • 1970-01-01
相关资源
最近更新 更多