我设法使用 Google Play Api 实现了这一点,并以动态/编程方式将产品上传到 Playstore。
首先我使用 PHP,因为我将 Laravel 用于我的后端 REST API。由您自己选择。我将使用 composer 安装 google/apiclient 库
使用composer require google/apiclient
https://developers.google.com/android-publisher/api-ref/inappproducts
https://developers.google.com/android-publisher/api-ref/inappproducts/insert
可以这样上传示例产品:
第 1 步:您需要对服务进行身份验证。如果您愿意,可以使用服务 json 文件或 Auth oath。就我而言,我使用了服务 json 文件并在我的 GCP 控制台中启用了 Google Play API。
第 2 步:您需要一个 sku(唯一)参考文档并查看所需格式
步骤 3: 您需要设置一个价格(微),您可以使用 https://github.com/Torann/laravel-currency 将一种货币转换为另一种货币商店(应用内产品)注意:货币必须匹配,否则会出错。
第 4 步:您需要设置列表,这些列表基本上是您的应用出于翻译目的所需的标题/描述
$client = new Google_Client();
$client->setAuthConfig(storage_path('service_account.json'));
// You have to add this scope so it knows it is in app billing store
$client->addScope('https://www.googleapis.com/auth/androidpublisher');
$service = new Google_Service_AndroidPublisher($client);
$body = new \Google_Service_AndroidPublisher_InAppProduct();
$body->setSku("unique_sku_here");
$body->setPackageName('android_app_package_name'); // e.g com.example.in_app_test
//1.00 USD = 1,000,000 Microns.
// Create a new price object
$price = new \Google_Service_AndroidPublisher_Price();
$price->setCurrency('USD');
//Using **torann/currency** library to convert from one currency to another
$new_price = intval(currency("1000", $from = "EUR", $to = "USD", false));
$price->priceMicros = $new_price * 1000000;
$body->setDefaultPrice($price);
// Setting the default language
$body->defaultLanguage = "en_US";
$body->setListings([
'en_US' => [
'title' => 'Product Title',
'description' => "Product Description here"
]
]);
$purchase = $service->inappproducts->insert(
'android_app_package_name',
$body,
[
'autoConvertMissingPrices' => true,
]);
$purchase->setStatus(true); // Always set this to mark the product active on the GPlay console.
这样您将获得成功上传产品的回报。
干杯。如果您有任何障碍,请随时发表评论,我很乐意澄清。