Google BigQuery asking Gmail Confirmation, Best way to handle in Production Environment -
i have created 1 c# console application read bigquery data.
while first running console application, opens browser window asking google acceptance, further times not asking permission in same machine.
question: asking permission each , every machine first time, if yes best way deploy bigquery application, bz client needs accept gmail access using developer id? makes sense or best way handle google bigquery application in production environment?
here code.
using google.apis.auth.oauth2; using system.io; using system.threading; using google.apis.bigquery.v2; using google.apis.bigquery.v2.data; using system.data; using google.apis.services; using system; namespace googlebigquery { public class class1 { private static void main() { usercredential credential; using (var stream = new filestream("client_secrets.json", filemode.open, fileaccess.read)) { credential = googlewebauthorizationbroker.authorizeasync( googleclientsecrets.load(stream).secrets, new[] { bigqueryservice.scope.bigquery }, "user", cancellationtoken.none).result; } // create , initialize bigquery service. use project name value // new project window applicationname variable. bigqueryservice service = new bigqueryservice(new baseclientservice.initializer() { httpclientinitializer = credential, applicationname = "project name" }); string query = "your query"; jobsresource j = service.jobs; queryrequest qr = new queryrequest(); qr.query = query; datatable dt = new datatable(); int = 0; queryresponse response = j.query(qr, "project id").execute(); if (response != null) { int colcount = response.schema.fields.count; foreach (var column in response.schema.fields) { dt.columns.add(column.name); } foreach (tablerow row in response.rows) { datarow dr = dt.newrow(); (i = 0; < colcount; i++) { dr[i] = row.f[i].v; } dt.rows.add(dr); } } else { console.writeline("response null"); } } } }
thanks, selvakumar s
i'm not expert in c#, can see using "googlewebauthorizationbroker" - that's indeed helper class open web page end-user authentication , authorization.
use instead oauth2serviceaccount machine2machine auth (https://developers.google.com/identity/protocols/oauth2serviceaccount).
for sample c# code, see "where can find serviceaccountcredential".
Comments
Post a Comment