How to obtain android app version code using Google Api? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to obtain android app version code using Google Api? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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 }

???

Answer

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

We are here to answer your question about How to obtain android app version code using Google Api? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji