美好的一天,我正在寻找一个如何从asp.net web项目更新谷歌融合表的例子。这在过去通过制作httpwebrequest是可能的,似乎谷歌已经改变了他们的api和我发现的例子不再有效。
从好的方面来说,谷歌发布了一个.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 :(得分: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进行了硬编码,因为这对我的应用程序有意义。