Update fusion table from .net

六月ゝ 毕业季﹏ 提交于 2020-01-07 06:41:11

问题


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:


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.



来源:https://stackoverflow.com/questions/19999419/update-fusion-table-from-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!