2013-11-15 58 views
0

好日子即時尋找如何更新一個asp.net web項目的谷歌融合表的例子。這在過去可以通過建立httpwebrequest來實現,似乎谷歌已經改變了他們的api,而我發現的例子已經不再適用。更新融合表從.net

加方谷歌已經發布了.NET客戶端來訪問谷歌的API https://code.google.com/p/google-api-dotnet-client/

,但我不能找到如何更新的融合表工作示例。此人也面臨同樣的問題

Posting a request to the new Fusion Table API v1.0 using VB.NET

任何幫助,將不勝感激

感謝

回答

0

我想你是問如何插入數據。以下是一個示例:

string timestamp = DateTime.Now.ToString("u").TrimEnd('Z'); //e.g. 2008-04-10 13:30:00 
string sql = "INSERT INTO " + tableId + " (Timestamp, MAC_Address, URL) VALUES ('" + timestamp + "','" + macAddress + "','" + url + "')" ; 
var response = fusiontablesService.Query.Sql(sql).Execute(); 

我正在使用服務帳戶;融合表是這樣設置的

private void InitializeFusiontables() 
{ 
    //uses a service account; the fusiontable is shared with the service account's email address 
    //https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2 

    var certificate = new X509Certificate2(privateKeyFile, "notasecret", X509KeyStorageFlags.Exportable); 

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

    // Create the service. 
    fusiontablesService = new FusiontablesService(new BaseClientService.Initializer() 
    { 
     HttpClientInitializer = credential, 
     ApplicationName = "snarf-service-2", //not sure if the name here matters or not 
    }); 

    this.dataTable = fusiontablesService.Table.Get(tableId).Execute(); //.List().Execute(); 

    eventLog.WriteEntry("Fusiontable successfully located"); 

    macAddress = "testmacaddress"; 
    InsertRow("testurl.com"); 
} 

我硬編碼tableId,因爲這對我的應用程序有意義。