adachsoft / google-play-publisher
google-play-publisher
Requires
- php: ^8.3
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- psr/clock: ^1
- psr/http-client: ^1
- psr/http-factory: ^1
Requires (Dev)
- adachsoft/php-code-style: ^0.7.3
- friendsofphp/php-cs-fixer: ^3.95
- nyholm/psr7: ^1.8.2
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A PHP library for publishing Google Play Store listings, Android App Bundle releases, release tracks, and one-time products through the Google Play Developer API.
Requirements
- PHP 8.3 or later.
- The
openssl,json, andmbstringPHP extensions. - A PSR-18 HTTP client and PSR-17 request/stream factories. Examples include Guzzle (
guzzlehttp/guzzle) or Symfony HttpClient with Nyholm PSR-7 (symfony/http-clientandnyholm/psr7).
The library requires the PSR interfaces, but you provide the concrete HTTP client and factories.
Installation
composer require adachsoft/google-play-publisher
composer require guzzlehttp/guzzle
Service-account setup
Enable the Google Play Developer API for the Google Cloud project, create a service account, and grant that account the required app permissions in Play Console under Users and permissions. Download its JSON key and store it outside the repository with access restricted to the application.
Never commit service-account keys or other credentials to source control.
Usage
Create the publisher
use AdachSoft\GooglePlayPublisher\GooglePlayPublisher;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
$factory = new HttpFactory();
$publisher = GooglePlayPublisher::create(
'/secure/path/google-play-service-account.json',
new Client(),
$factory,
$factory,
);
create() uses the library's SystemClock by default. A PSR-20 ClockInterface implementation can be passed as the optional final argument.
Publish store listings
The reference listing input is docs/reference/play-listing.json. Its image paths are resolved relative to the base directory passed to StoreListingConfig::fromArray().
use AdachSoft\GooglePlayPublisher\Listing\StoreListingConfig;
$projectRoot = getcwd();
$listingData = json_decode(
(string) file_get_contents($projectRoot . '/docs/reference/play-listing.json'),
true,
512,
JSON_THROW_ON_ERROR,
);
$listing = StoreListingConfig::fromArray($listingData, $projectRoot);
$result = $publisher->listings()->publish($listing);
Set the optional second argument to publish() to true to discard the edit as a dry run.
Publish releases and inspect tracks
A release request can upload a bundle to the internal track, then publish the same version to production using its returned version code.
use AdachSoft\GooglePlayPublisher\Release\ReleaseRequest;
$internal = $publisher->releases()->publish(new ReleaseRequest(
packageName: 'com.example.game',
track: 'internal',
status: 'completed',
aabPath: '/build/app-release.aab',
releaseNotes: ['en-US' => 'Initial internal release.'],
));
$production = $publisher->releases()->publish(new ReleaseRequest(
packageName: 'com.example.game',
track: 'production',
status: 'completed',
existingVersionCode: $internal->versionCode,
releaseNotes: ['en-US' => 'Now available in production.'],
));
$tracks = $publisher->releases()->getTracks('com.example.game');
Publish one-time products
The reference input format is docs/reference/play-products.json. Pass one product definition from its products array to OneTimeProductDefinition::fromArray(). Before publishing products, upload a build containing the Google Play Billing permission to a track.
use AdachSoft\GooglePlayPublisher\Product\OneTimeProductDefinition;
$productsData = json_decode(
(string) file_get_contents($projectRoot . '/docs/reference/play-products.json'),
true,
512,
JSON_THROW_ON_ERROR,
);
$product = OneTimeProductDefinition::fromArray($productsData['products'][0]);
$result = $publisher->products()->publish('com.example.game', $product);
printf("Published %s with %d regions at home price %.2f.\n", $result->sku, $result->regionCount, $result->homePrice);
The configured home-region price is preserved exactly; Google Play's converted prices are used for other regions. The publisher uses regions version 2025/03 by default. Pass a different regions version to OneTimeProductPublisher when constructing it directly.
Errors
InvalidCredentialsException: credentials could not be read or validated.InvalidStoreListingExceptionandInvalidProductDefinitionException: invalid listing or product input. Both expose all detected problems throughproblems.InvalidArgumentException: invalid release request fields or combinations.AuthenticationException: service-account signing or OAuth token request/response failure.ApiRequestException: a Google Play API request returned a non-2xx status; the exception includes the method, URL, status, and response body.InvalidApiResponseException: a Google Play API response is invalid or does not match the expected structure.RuntimeException: a configured local image or Android App Bundle file could not be read.