【问题标题】:How to set Google Play `inAppUpdatePriority` using google-php-api-client如何使用 google-php-api-client 设置 Google Play `inAppUpdatePriority`
【发布时间】:2022-05-03 20:53:11
【问题描述】:

我在https://issuetracker.google.com/issues/133299031#comment14找到了以下主题

您好,可以使用 Play Developer Publishing API 的⁠Edits methods 设置版本的应用内更新优先级。在 ⁠Edits.tracks.releases 下有一个新的“inAppUpdatePriority”字段。该文档尚未提及新字段,但您仍然应该能够设置它。目前无法从 Google Play 管理中心设置应用内更新优先级。

我正在使用带有服务帐户身份验证的 google-api-php-client,我想问一下如何使用 google-api-php-client 设置“inAppUpdatePriority”,我已尝试在我的 PHP 代码中执行以下操作。

$publisher->edits_tracks->update(self::PACKAGE_NAME, self::EDIT_ID, 'production', new \Google_Service_AndroidPublisher_Track); 

【问题讨论】:

  • 你能找到任何解决方案吗,我也在寻找解决方案

标签: php android google-api-php-client google-play-developer-api


【解决方案1】:

在使用 Google API PHP Client 进行数小时测试后,我设法使用 Laravel 编辑了 inAppUpdatePriority 字段,如下所示:

try {
   $packageName = "your.package.name";
   $versionCode = "version_code_as_string"; //example "50"
   $client = new \Google\Client();

   //you need to setup your own Service Account or other API access methods
   $client->setAuthConfig("path/to/your/json/file");
   $client->addScope(AndroidPublisher::ANDROIDPUBLISHER);
   $service = new \Google\Service\AndroidPublisher($client);

   //create new edit
   $appEdit = $service->edits->insert($packageName, new \Google\Service\AndroidPublisher\AppEdit());

   //uncomment if you want to get hold of available tracks
   // $tracksResponse = $service->edits_tracks->listEditsTracks($packageName, $appEdit->id);
   // dd($tracksResponse);

   $trackRelease = new \Google\Service\AndroidPublisher\TrackRelease();
   $trackRelease->versionCodes = [$versionCode];

   //set desired update priority
   $trackRelease->inAppUpdatePriority = 5;
   $trackRelease->status = "completed";
   $postBody = new \Google\Service\AndroidPublisher\Track();
   $postBody->setReleases([$trackRelease]);

   //desired track to update. One of the followings: production,beta,alpha,internal
   $track = "production";
   $update = $service->edits_tracks->update($packageName, $appEdit->id, $track, $postBody);
   //commit changes to Google Play API
   $service->edits->commit($packageName, $appEdit->id);
   // dd($update);
} catch (Exception $ex) {
   if ($ex->getCode() == 404) {
       //this catches if some info is wrong (tested with a version code that has not been upload to Google Play Console)
   }
}

注意事项:

  1. 您应该注意,要使其正常工作(无需实施通过 Google Play API 上传应用的适当方式),您需要首先通过 Google Play 控制台将您的应用上传到您想要的轨道,然后点击 保存,然后 Review release 和 */!\DON'T CLICK Rollout release/!*,然后运行上面提到的代码,它将提交(推出)更改(如果您在运行上述代码后尝试推出版本,您将收到一个可以忽略的错误。
  2. 如果您的版本已经发布,则不会应用对 inAppUpdatePriority 的任何更改。
  3. 您应该已经在所需轨道中发布了至少一个版本,然后才能使用它(仅通过内部测试进行测试)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2019-09-19
    相关资源
    最近更新 更多