-1

我的桌面應用程序使用www.google.com/accounts/ClientLogin(目前不可用)獲得認證令牌,那麼我用來從非官方市場API的Android應用程序信息(https://androidquery.appspot.com/api/market?app=(put包姓名))如何使用Google Api獲取Android應用版本代碼?

現在谷歌希望我使用OAuth授權,因爲ClientLogin不推薦使用並且始終響應404。

所以問題是 - 如何通過「appId」(例如版本代碼 - 「23」)使用OAuth 2.0和Google客戶端Api庫for .NET獲得android應用程序信息?

而另一個問題 - 如何可以手動生成該請求

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

的User-Agent:谷歌-API的dotnet的客戶端/ 1.9.3.19379(gzip的)

內容類型:應用/ X WWW的窗體-urlencoded

主機:accounts.google.com

的Content-Length:750

連接:Keep-Alive

assertion =?

我可以在Fiddler中看到這個請求是如何從google lib發送的?但它存儲內部LIB的響應,並且我不能訪問到的身份驗證令牌:

{ 「的access_token」: 「TOKEN_HERE」, 「token_type」: 「承載」, 「expires_in」:3600}

???

回答

0

我找到了解決這個問題的方法。

Google Api提供了一種獲取應用版本代碼的方法。

首先,您需要在Google Developers Console中創建項目,並使用p12密鑰文件創建服務帳戶的憑據。 並啓用Google Play Developers Api。

在Google Play Developers Console中,您應該將您的應用鏈接到此項目。

後,你可以這樣寫代碼eour桌面.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; 

就是這樣。 希望這個答案有助於某人=)

相關問題