3

我需要使用Google BigQuery API查詢數據,並使用服務帳戶進行調用。Google BigQuery with C#示例示例

但是我很努力地找到.NET示例,並且沒有包含在二進制文件(Google.Apis.Bigquery.dll)中的文檔。任何人都可以爲我提供C#.NET的示例用法嗎?

+0

的可能重複的[谷歌大量查詢與.NET文檔/樣品](http://stackoverflow.com/questions/12443878/google-bigquery-with-net-documentation-samples) – Eluvatar

+0

嗨,先生,這是一個過時的例子和過時的命名空間,甚至我正在尋找服務帳戶以及最新的NUGET pacakge命名空間信息的例子。 – user3508580

回答

3

此信息來自哪裏:Google APIs Client Library for .NET

這個例子說明如何使用了Google+ API服務帳戶。爲了與BigQuery一起使用,我對它進行了編輯。

using System; 
using Google.Apis.Auth.OAuth2; 
using System.Security.Cryptography.X509Certificates; 
using Google.Apis.Bigquery.v2; 
using Google.Apis.Services; 

//Install-Package Google.Apis.Bigquery.v2 
namespace GoogleBigQueryServiceAccount 
{ 
class Program 
{ 
    private static String ACTIVITY_ID = "z12gtjhq3qn2xxl2o224exwiqruvtda0i"; 
    static void Main(string[] args) 
    { 

     Console.WriteLine("BigQuery API - Service Account"); 
     Console.WriteLine("=========================="); 

     String serviceAccountEmail = "SERVICE_ACCOUNT_EMAIL_HERE"; 

     var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable); 

     ServiceAccountCredential credential = new ServiceAccountCredential(
      new ServiceAccountCredential.Initializer(serviceAccountEmail) 
      { 
       Scopes = new[] { BigqueryService.Scope.DevstorageReadOnly } 
      }.FromCertificate(certificate)); 

     // Create the service. 
     var service = new BigqueryService(new BaseClientService.Initializer() 
     { 
      HttpClientInitializer = credential, 
      ApplicationName = "BigQuery API Sample", 
     }); 

     //Note: all your requests will run against Service. 

    } 
} 

}

+0

謝謝,我明白了...... – user3508580

+0

什麼是「notasecret」?會去這裏嗎? – tommed

+1

它只是文本保持原樣 – DaImTo