Ho bisogno di interrogare i dati usando Google BigQuery API. Ma sto cercando di trovare gli esempi .NET e non è stata fornita alcuna documentazione con il file binario (Google.Apis.Bigquery.dll). Qualcuno può fornirmi l'utilizzo di esempio per .NET?Google BigQuery con documentazione/campioni .NET
risposta
Non abbiamo ancora alcun campione di BigQuery C#, ma la libreria di Google .NET viene fornita con vari esempi per altre API di Google e il codice è simile. See this page for an example.
Il codice avrà un aspetto simile al seguente (nota: non ho ancora avuto la possibilità di testarlo ancora, quindi le modifiche sono benvenute ...). A proposito, stiamo facendo molti aggiornamenti di documentazione per BigQuery e speriamo di pubblicare alcuni campioni C# non appena possibile (ma molto probabilmente il prossimo mese).
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Bigquery.v2;
using Google.Apis.Util;
{
public class Program
{
public static void Main(string[] args)
{
// Register an authenticator.
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
// Put your client id and secret here (from https://developers.google.com/console)
// Use the installed app flow here.
provider.ClientIdentifier = "<client id>";
provider.ClientSecret = "<client secret>";
// Initiate an OAuth 2.0 flow to get an access token
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
// Create the service.
var service = new BigqueryService(auth);
// Do something with the BigQuery service here
// Such as... service.[some BigQuery method].Fetch();
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { BigqueryService.Scopes.Bigquery.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
}
}
Questi campioni o documentazione sono già stati creati? Non riesco ancora a rintracciarli, ho trovato i documenti API che sono belli, ma non danno davvero un buon punto di partenza! – Ben
cosa è Google.Apis.Util, GoogleAuthenticationServer, NativeApplicationClient per favore pubblica qualche spiegazione per le dipendenze. Inoltre, qualche possibilità hai campioni? – Cherven
Quando scarico la libreria Google Api più recente tramite NuGet https://www.nuget.org/packages/Google.Apis/ non riconosce 'Google.Apis.Authentication'. È una versione funzionante del codice che hai incollato sopra? Se la libreria Java è meno complicata, fatecelo sapere, così passiamo a quello. – Disasterkid
Ecco un esempio di lavoro, basato in parte fuori della risposta di Michael:
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 your client ID and secret here (from https://developers.google.com/console)
// Use the installed app flow here.
// Client ID looks like "9999999.apps.googleusercontent.com"
static string clientId = "YOURCLIENTID";
static string clientSecret = "YOURSECRET";
// Project ID is in the URL of your project on the APIs Console
// Project ID looks like "999999";
static string projectId = "YOURPROJECTID";
// Query in SQL-like form
static string query = "SELECT state, count(*) from [publicdata:samples.natality] GROUP BY state ORDER BY state ASC";
public static void Main(string[] args)
{
// Register an authenticator.
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = clientId;
provider.ClientSecret = clientSecret;
// Initiate an OAuth 2.0 flow to get an access token
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
// Create the 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 to exit");
Console.ReadLine();
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { BigqueryService.Scopes.Bigquery.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
}
}
Questo utilizza le query sincrone. Per le query asincrone, il codice sarebbe leggermente diverso.
È necessario fare riferimento sia alla DLL del servizio BigQuery (nella directory "Servizi" nel download binario), sia alle altre DLL nella directory "Lib". versione binaria è qui: http://code.google.com/p/google-api-dotnet-client/wiki/Downloads#Latest_Stable_Release
Il codice .NET sta per essere molto simile al codice della libreria Java (sono generati fuori della stessa descrizione API): https://developers.google.com/bigquery/docs/developers_guide#batchqueries
ci arriveremo più campioni là fuori presto, ma spero che questo aiuti nel frattempo.
per uno recente, vedere http://bitvectors.blogspot.de/2014/05/front-end-google -bigquery-with-aspnet_27.html –
La libreria che hai collegato richiede Windows 8.1 e tutti i suoi pacchetti NuGet devono essere risolti. Ho visto alcuni dei tuoi video su YouTube su Big Query. Le istruzioni 'using' usate nello snippet di codice sopra non funzionano con il resto del codice. Se la libreria Java è più stabile per favore fammelo sapere, così passiamo a quello. – Disasterkid
- 1. Google BigQuery Elimina righe?
- 2. Join su Google Bigquery
- 3. Sincronizzare Amazon RDS con Google BigQuery
- 4. Come pivot in Google BigQuery
- 5. Google BigQuery - come rilasciare la tabella con il comando bq?
- 6. Esportazione da Google BigQuery in CloudSQL?
- 7. Pagina stato di sistema di Google BigQuery?
- 8. Cosa significa campo RIPETUTO in Google Bigquery?
- 9. Impaginazione BigQuery
- 10. Visualizza con parametri in BigQuery
- 11. Bigquery selezionare valori distinti
- 12. Google BigTable vs BigQuery per memorizzare gran numero di eventi
- 13. Come connettiamo Azure Machine Learning Studio a Google BigQuery?
- 14. Creazione/scrittura nella tabella BigQuery parititoned tramite Google Cloud Dataflow
- 15. Google Cloud Dataflow ETL (Datastore -> Transform -> BigQuery)
- 16. Come impostare scadenza per BigQuery su Google App Engine
- 17. Inserire messaggi PubSub in BigQuery tramite Google Cloud Dataflow
- 18. Bigquery - autorizzazione solo scrittura
- 19. Google Wave per .Net
- 20. Utilizzo di BigQuery con R per l'analisi dei dati
- 21. BigQuery tipi di dati
- 22. Variazioni dei prezzi di Bigquery?
- 23. BigQuery ISCRIVITI errore
- 24. API .NET per Google Talk?
- 25. Accesso con FB Connect/Google OAuth in .NET
- 26. join bigquery su nidificato ripetuto
- 27. Come creare una vista BigQuery
- 28. Autenticazione dell'API di Google con un account di servizio con API Java
- 29. Pro e contro di BigQuery rispetto a Amazon Redshift
- 30. API di Google Analytics e .Net
Si prega di consultare le risposte di seguito-- hanno aiutato? –
Facci sapere se hai bisogno di ulteriore aiuto. Se le risposte sotto funzionano, si prega di votare su/accettare. Grazie! –
Per uno recente, vedere http://bitvectors.blogspot.de/2014/05/front-end-google-bigquery-with-aspnet_27.html –