1

这是我的代码,根据'fusion_tables' gem 文档。显然,我不会在此代码中发布我的用户名和密码。

require 'fusion_tables'

@ft = GData::Client::FusionTables.new      
@ft.clientlogin(my_google_account_name, my_google_account_password)

# Creating a new table
columns = [
    {
        :name=>"column_1",
        :type=>'string'
    }, 
    {
        :name=>"column_2",
        :type=>'number'
    }
]

new_table = @ft.create_table "Ruby table",columns

# Inserting rows
data = [
    {
    "column_1"=>"This is a string",
    "column_2"=>100
    }
]

new_table.insert data

当我运行它时,我得到这个错误:

<HEAD>
<TITLE>User does not have permission to view the underlying data</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>User does not have permission to view the underlying data</H1>
<H2>Error 403</H2>
</BODY>
</HTML>

我该如何解决这个问题?

4

1 回答 1

1

看起来create_table method在 gem 中有点过时了。

我尝试了上面的示例,以及gem repo中提供的 boris_bikes 示例fusion_tables。两者都在调用方法的行上抛出Error 403 User does not have permission to view the underlying data错误消息。create_table

在上面的示例中,引发此错误的行是:

new_table = @ft.create_table "Ruby table",columns

虽然创建了“Ruby_table”融合表。(注意fusion_tablegem会清理表名,即它用下划线替换给定名称中的空格。)

最近,Google Fusion table API 很可能在这个 gem 上发生了一些变化。我在 repo 上开了一个新问题;希望开发商能尽快做出回应。(或者如果时间允许,我会深入研究,找出原因,然后提交补丁)

现在,我建议忽略错误并在创建表后继续前进。

运行该new_table = @ft.create_table "Ruby table",columns行后,继续执行以下步骤:

tables = @ft.show_tables
new_table  = tables.select{|t| t.name == "Ruby_table" }.first

# Inserting rows
data = [ 
 { 
    "column_1"=>"This is a string",
    "column_2"=>100
  }
]

new_table.insert data

这样,您应该会在 Fusion Table 中看到该行。

在我的一个生产应用程序上,我们手动创建了所需的 Fusion Tables - 将其与现有数据表(目前尚不支持 API)合并,然后使用truncate&insert方法更新 Fusion 表数据。因此,无法以编程方式创建 Fusion Table 对我们来说并不是一个大问题。

于 2012-10-22T03:35:39.550 回答