public async Task FromStreamAsync_ServiceAccountCredential() { var stream = new MemoryStream(Encoding.UTF8.GetBytes(DummyServiceAccountCredentialFileContents)); var credential = await GoogleCredential.FromStreamAsync(stream, CancellationToken.None); Assert.IsType <ServiceAccountCredential>(credential.UnderlyingCredential); Assert.True(credential.IsCreateScopedRequired); var serviceCred = (ServiceAccountCredential)credential.UnderlyingCredential; Assert.Equal("CLIENT_EMAIL", serviceCred.Id); Assert.Equal("PROJECT_ID", serviceCred.ProjectId); }
public static async Task SetUpSheet() { using (var stream = new FileStream("credentials.dat", FileMode.Open, FileAccess.ReadWrite)) { //f**k OATH 2.0 for console apps, that shit does not belong in a console app. credential = await GoogleCredential.FromStreamAsync(stream, CancellationToken.None); } // Create Google Sheets API service. service = new SheetsService(new() { HttpClientInitializer = credential, ApplicationName = ApplicationName, });; }
private async Task <SheetsService> GetSheetsService() { using (var keyStream = new FileStream(_settings.Value.GoogleKeyFile, FileMode.Open, FileAccess.Read)) { var credentials = (await GoogleCredential.FromStreamAsync(keyStream, CancellationToken.None)) .CreateScoped(GoogleScopes) .CreateWithUser(_settings.Value.GoogleDelegatedAuthority); return(new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = credentials, ApplicationName = GoogleAppName, GZipEnabled = true })); } }
public override async Task <bool> VerifyReceipt(string token, string productId) { try { string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GoogleCredential.json"); GoogleCredential credential; using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { credential = (await GoogleCredential.FromStreamAsync(stream, System.Threading.CancellationToken.None)) .CreateScoped(AndroidPublisherService.Scope.Androidpublisher); } var service = new AndroidPublisherService(new BaseClientService.Initializer() { HttpClientInitializer = credential, //ApplicationName = ApplicationName, }); var request = service.Purchases.Products.Get(PackageName, productId, token); var purchase_state = await request.ExecuteAsync(); ProductId = purchase_state.ProductId; marketPurchaseTime = (long)purchase_state.PurchaseTimeMillis; marketOrderId = purchase_state.OrderId; //var request2 = service.Inappproducts.Get(PackageName, productId); //var state = await request2.ExecuteAsync(); //var prices = state.Prices; } catch (Exception ex) { Log.Error(ex.ToString()); return(false); } return(true); }