integration - How to integrate Google Bigquery with c# console application -
if possible integrate google big query c# console application?.
if yes how can do, searched on internet not find proper answer that.
i want connection string format? have created client id google developer console how authentication has done? 1 time configuration or every time need login in google account authenticate.
if there sample application connect sample data helpful.
thanks, selvakumar s
here's working sample based on another question in stackoverflow:
using dotnetopenauth.oauth2; using google.apis.authentication.oauth2; using google.apis.authentication.oauth2.dotnetopenauth; using google.apis.bigquery.v2; using google.apis.bigquery.v2.data; using google.apis.util; using system; using system.diagnostics; using system.collections.generic; namespace bigqueryconsole { public class bigqueryconsole { // put client id , secret here (from https://developers.google.com/console) // use installed app flow here. // client id looks "9999999.apps.googleusercontent.com" static string clientid = "yourclientid"; static string clientsecret = "yoursecret"; // project id in url of project on apis console // project id looks "999999"; static string projectid = "yourprojectid"; // query in sql-like form static string query = "select state, count(*) [publicdata:samples.natality] group state order state asc"; public static void main(string[] args) { // register authenticator. var provider = new nativeapplicationclient(googleauthenticationserver.description); provider.clientidentifier = clientid; provider.clientsecret = clientsecret; // initiate oauth 2.0 flow access token var auth = new oauth2authenticator<nativeapplicationclient>(provider, getauthorization); // create service. var service = new bigqueryservice(auth); jobsresource j = service.jobs; queryrequest qr = new queryrequest(); qr.query = query; queryresponse response = j.query(qr, projectid).fetch(); foreach (tablerow row in response.rows) { list<string> list = new list<string>(); foreach (tablerow.fdata field in row.f) { list.add(field.v); } console.writeline(string.join("\t", list)); } console.writeline("\npress enter exit"); console.readline(); } private static iauthorizationstate getauthorization(nativeapplicationclient arg) { // auth url: iauthorizationstate state = new authorizationstate(new[] { bigqueryservice.scopes.bigquery.getstringvalue() }); state.callback = new uri(nativeapplicationclient.outofbandcallbackurl); uri authuri = arg.requestuserauthorization(state); // request authorization user (by opening browser window): process.start(authuri.tostring()); console.write(" authorization code: "); string authcode = console.readline(); console.writeline(); // retrieve access token using authorization code: return arg.processuserauthorization(authcode, state); } } }
Comments
Post a Comment