我正在尝试弄清楚如何使用Google Play自定义应用发布API 使用C#发布私人应用程序,我找不到上载或传递APK的方法。
文档here给出了操作方法的示例:
Path apkPath = Paths.get("PATH_TO_APK");
ByteArrayContent apk =
new ByteArrayContent("application/octet-stream", Files.readAllBytes(apkPath));
CustomApp appMetadata =
new CustomApp()
.setTitle("APPLICATION TITLE").setLanguageCode("en_US");
CustomApps.Create request =
apiClient.accounts() // Playcustomapp apiClient
.customApps().create(DEV_ACCOUNT_ID, appMetadata, apk);
CustomApp response = request.execute();
我已经导入了NuGet软件包Google.Apis.Playcustomapp.v1
,并创建了appMetaData
CustomApp appMetadata = new CustomApp() {
Title = "Whatsapp",
LanguageCode = "en-US"
};
有2个API请求可用,它们是:
var createRequest = new AccountsResource.CustomAppsResource.CreateRequest(
service, appMetadata, 9197907806840XXXXX);
var createMediaUpload = new AccountsResource.CustomAppsResource.CreateMediaUpload(
service, appMetadata, 9197907806840XXXXX, ms, "application /octet-stream");
两者都给我错误404。这是因为我没有通过需要上传的APK。
我可以从哪里发送此APK? stream
中有一个CreateMediaUpload
参数,但它也无济于事。
错误:
CreateRequest
:解析值<时遇到意外字符。路径“。如何在此处通过APK
的路径?
CreateMediaUpload
:在此服务器上找不到请求的URL /upload/9197907806840917992/customApps?uploadType=resumable
。
有人可以帮我吗?
答案 0 :(得分:0)
您找到的文档是Java示例。经过对如何将各个部分组合在一起的随机猜测之后,我终于明白了。
请记住,对于每天创建私人应用的频率有一些未公开的不可思议的限制。大约每天15个应用程序。在达到该限制之后,您将收到以下消息错误:
apkNotificationMessageKeyReachedUploadLimit
static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}
static async Task MainAsync(string[] args)
{
var email = "yourserviceaccountmail";
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(email)
{
Scopes = new[] { PlaycustomappService.Scope.Androidpublisher }
}.FromPrivateKey("client_secrets.json"));
CustomApp appMetadata = new CustomApp();
appMetadata.Title = "YOUR APP";
appMetadata.LanguageCode = "en_US";
// Create the service.
var service = new PlaycustomappService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Custom Apps API Sample",
});
var acc = new AccountsResource(service);
using (var stream = new FileStream("app-release.apk", FileMode.Open))
{
long devIAccountd = 12345678L;
var app = acc.CustomApps.Create(appMetadata, devIAccountd, stream, "application/octet-stream");
var response = await app.UploadAsync();
if (response.Exception != null)
{
Console.WriteLine("Someting went wrong:");
Console.WriteLine(response.Exception.Message);
}
if (response.Status == Google.Apis.Upload.UploadStatus.Completed)
{
Console.WriteLine("Succeeded!");
}
}
}