phpandroidgoogle-api-php-clientgoogle-play-developer-api

How to set Google Play `inAppUpdatePriority` using google-php-api-client


I found following thread at : 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.

I am using google-api-php-client with Service Account authentication, I would like to ask how to set 'inAppUpdatePriority' using google-api-php-client I have tried following in my PHP code.

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

Solution

  • After hours of testing with Google API PHP Client, I managed to edit the inAppUpdatePriority field, with Laravel, this way:

    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)
       }
    }
    

    Notes:

    1. You should note that for this to work (without implementing your propre way of uploading app via Google Play API), you need to first upload your app via Google Play Console to your desired track, then click Save, then Review release and */!\DON'T CLICK Rollout release/!*, then run the above mentioned code which will Commit (Rollout) the changes (if you try to rollout release after running the above code, you will get an error that you can ignore).
    2. Any changes to inAppUpdatePriority won't be applied if your release is already rolled out.
    3. You should have already published at least one release in the desired track before you can use this (tested with Internal testing only)