问题
Here's my code, as per the 'fusion_tables' gem documentation. Obviously, I don't post my username and password in this code.
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
When I run it, I get this error:
<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>
How do I fix this problem?
回答1:
Looks like create_table method
in the gem is a bit outdated.
I tried the example above, and the boris_bikes example provided in the fusion_tables gem repo. Both throw the Error 403
User does not have permission to view the underlying data
error message on the line invoking create_table
method.
In the above example, the line throwing this error is:
new_table = @ft.create_table "Ruby table",columns
The "Ruby_table" fusion table though is created. ( NOTE: The fusion_table
gem sanitizes the table name, i.e. it substitutes the spaces in the given name with an underscore. )
Most likely the Google Fusion table API has changed a bit on this gem in recent times. I have opened a new issue on the repo; hopefully the developers will respond to it soon. (Or if time permit, I will dig into it, figure out the reasons, and submit a patch)
For now, I would suggest ignoring the error and continuing forward since the table is created.
After running the new_table = @ft.create_table "Ruby table",columns
line, continue with the following steps:
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
With that you should see the line show up in the Fusion Table.
On one of my Production Apps, we manually created the required Fusion Tables - merged it with existing Data tables (for which there is no API support as of now), and then use the truncate
& insert
methods to update the Fusion table data. So not being able to create a Fusion Table programmatically didn't come up as a big issue for us there.
来源:https://stackoverflow.com/questions/13004134/why-am-i-getting-a-403-error-when-creating-a-fusion-table-using-the-ruby-gem-fu