gpt4 book ai didi

php - 如何使用 google-php-api-client 设置 Google Play `inAppUpdatePriority`

转载 作者:行者123 更新时间:2023-12-05 05:03:18 26 4
gpt4 key购买 nike

我发现以下线程:https://issuetracker.google.com/issues/133299031#comment14

Hello, In-app update priority of the release can be set using the Play Developer Publishing API's ⁠Edits methods. There is a new 'inAppUpdatePriority' field under ⁠Edits.tracks.releases. The documentation does not mention the new field yet but you should still be able to set it. In-app update priority can not be set from the Google Play Console at the moment.

我正在使用带有服务帐户身份验证的 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); 

最佳答案

经过数小时的测试 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 控制台将您的应用上传到您想要的轨道,然后点击保存,然后是审核发布和*/!\DON'T CLICK Rollout release/!*,然后运行上面提到的代码,这将提交(发布)更改(如果您在运行上述代码后尝试推出版本,您将收到一个您可以忽略的错误。
  2. 如果您的版本已经推出,则不会应用对 inAppUpdatePriority 的任何更改。
  3. 您应该已经在所需轨道中发布了至少一个版本,然后才能使用它(仅通过内部测试进行测试)

关于php - 如何使用 google-php-api-client 设置 Google Play `inAppUpdatePriority`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61725683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com