-1

My desktop app used www.google.com/accounts/ClientLogin (which currently unavailable) to obtain authentification token, that i used to get android application info from unofficial market api (https://androidquery.appspot.com/api/market?app=(put the package name here))

Now Google want me to use OAuth authorization because ClientLogin deprecated and response 404 all time.

So question is - how can i get android application info by "appId" (just version code for example - "23") using OAuth 2.0 and Google Client Api Libraries for .NET?

And another question - how i can manually generate this request

POST "https://accounts.google.com/o/oauth2/token HTTP/1.1"

User-Agent: google-api-dotnet-client/1.9.3.19379 (gzip)

Content-Type: application/x-www-form-urlencoded

Host: accounts.google.com

Content-Length: 750

Connection: Keep-Alive

assertion=?

I can see in Fiddler how this request send from google lib? but it stores the response inside lib and i can't access to auth token:

{ "access_token" : "TOKEN_HERE", "token_type" : "Bearer", "expires_in" : 3600 }

???

dodger_dev
  • 46
  • 4

2 Answers2

1

I found solution for this problem.

Google Api provides one method to obtain apllication version code.

Firstly, you need to create a project in Google Developers Console, create credentials for Service Account with p12 key file. And enable Google Play Developers Api.

In Google Play Developers Console you should link your app to this project.

After, you can write this code in eour desktop .NET appliation:

var serviceAccountEmail = "YOUR Service Account Email";
        var certificate = new X509Certificate2(@"key.p12", "YOUR_CLIENT_SECRET", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(serviceAccountEmail)
                {
                    Scopes = new[] { AndroidPublisherService.Scope.Androidpublisher }
                }.FromCertificate(certificate));

        var service = new AndroidPublisherService(
            new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Edits Sample"
                });
        var apiEditBody = new AppEdit();
        // packageName - your app id like com.myapp.test
        var appEdit = service.Edits.Insert(apiEditBody, packageName)
            .Execute();

        var list = service.Edits.Apks.List(packageName, appEdit.Id)
            .Execute()
            .Apks;

        var deletingEditResult = service.Edits.Delete(packageName, appEdit.Id).Execute();
        var versionCode = list.Last().VersionCode.Value;

That's it. Hope, this answer will help somebody =)

dodger_dev
  • 46
  • 4
0

Similar to solution above which was very helpful to me, here is a solution that gets the latest production track version code of your app using the Google API's:

        var path = "PATH_TO_JSON_KEY";
        var credential = GoogleCredential.FromFile(path).CreateScoped(AndroidPublisherService.Scope.Androidpublisher);
        var service = new AndroidPublisherService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Production Version Checker" });
        var appEdit = service.Edits.Insert(new AppEdit(), "com.package.name").Execute();
        var listTracks = service.Edits.Tracks.List("com.package.name", appEdit.Id).Execute();
        var productionTrack = listTracks.Tracks.FirstOrDefault(t => t.TrackValue == "production");
        var latestProductionRelease = productionTrack.Releases.FirstOrDefault(r => r.Status == "completed");
        var latestProductionVersionCode = latestProductionRelease.VersionCodes.FirstOrDefault();
        var deletingEditResult = service.Edits.Delete("com.package.name", appEdit.Id).Execute();