Update fusion table from .net

2019-08-20 08:55发布

Good Day im looking for an example of how to update a google fusion table form a asp.net web project. This was possible in the past through making an httpwebrequest, it seems google has changed their api's and the examples i found no longer works.

On the plus side Google has released a .net client to access the google apis https://code.google.com/p/google-api-dotnet-client/

but i cannot find a working sample of how to update a fusion table. This person is also facing the same problem

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

Any help would be greatly appreciated

Thanks

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-20 09:34

I think you are asking how to insert data. Here is an example:

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();

I'm using a Service Account; the fusion table is set up like this

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");
}

I hard coded the tableId because that makes sense for my application.

查看更多
登录 后发表回答