我的桌面应用使用www.google.com/accounts/ClientLogin(目前无法使用)来获取身份验证令牌,我曾经从非官方市场api获取Android应用信息(https://androidquery.appspot.com/api/market?app=(put这里的包名称))
现在,Google希望我使用OAuth授权,因为ClientLogin已弃用并且始终响应404。
所以问题是 - 如何通过" appId"获取Android应用程序信息? (仅使用版本代码 - " 23")使用OAuth 2.0和Google Client Api Libraries for .NET?
另一个问题 - 我如何手动生成此请求
POST" https://accounts.google.com/o/oauth2/token HTTP / 1.1"
User-Agent:google-api-dotnet-client / 1.9.3.19379(gzip)
内容类型:application / x-www-form-urlencoded
主持人:accounts.google.com
内容长度:750
连接:Keep-Alive
断言=?
我可以在Fiddler中看到这个请求是如何从谷歌lib发送的?但它将响应存储在lib中,我无法访问身份验证令牌:
{ "&的access_token#34; :" TOKEN_HERE", " token_type" :" Bearer", " expires_in" :3600 }
???
答案 0 :(得分:0)
我找到了解决这个问题的方法。
Google Api提供了一种获取应用版本代码的方法。
首先,您需要在Google Developers Console中创建项目,使用p12密钥文件为服务帐户创建凭据。 并启用Google Play开发人员Api。
在Google Play开发者控制台中,您应该将应用链接到此项目。
之后,您可以在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;
就是这样。 希望,这个答案可以帮助某人=)
答案 1 :(得分:0)
类似于上面的解决方案,这对我非常有帮助,这是一个使用Google API获取您应用的最新生产跟踪版本代码的解决方案:
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();