google spreadsheet access denied error

1,890 views
Skip to first unread message

quarkLore

unread,
Mar 20, 2008, 2:17:56 AM3/20/08
to Google Visualization API
I have created a google spreadsheet and use google visualization API
to access the data and pick up a single row and display it. It works
fine when my browser is logged google account but when it is not then
it gives an access denied error.


I have published the spreadsheet and made it viewable by all. I can
view the spreadsheet without logging in gmail account:
http://spreadsheets.google.com/pub?key=pkv_7X5t9HXVu4ZxZ-znSEA

Following is the code:
--------------------------------

<table bgcolor="black">
<tbody><tr>
<td><span style="color: rgb(0, 255, 0);">root@matrix:>

<div id="quote"> </div>
<script src="http://www.google.com/jsapi" type="text/javascript"></
script>
<script type="text/javascript">
google.load("visualization", "1");
function initialize() {
var query = new google.visualization.Query("http://
spreadsheets.google.com/tq?key=pkv_7X5t9HXVu4ZxZ-znSEA&gid=0");
query.send(handleQueryResponse); // Send the query with a
callback function
}
google.setOnLoadCallback(initialize); // Set callback to run
when API is loaded

// Query response handler function.
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' +
response.getDetailedMessage());
return;
}

var data = response.getDataTable();
var html = [];
var rows = data.getNumberOfRows();
var index = parseInt ("" + Math.random() * rows + "" );
html.push (data.getFormattedValue (index,0));
document.getElementById('quote').innerHTML = html.join('');

}
</script>

</span><img width="20" src="http://prateek.mac.googlepages.com/
blinking_cursor2.gif" height="16"/>
</td>
</tr>
</tbody></table>

VizGuy (Google)

unread,
Mar 20, 2008, 6:10:43 AM3/20/08
to Google Visualization API
Short answer:
Use this URL; http://spreadsheets.google.com/tq?key=pkv_7X5t9HXVu4ZxZ-znSEA&pub=1

Long Answer:
Spreadsheets have 2 permission levels: Live data and published data.
Live data permissions are controlled by the permissions in the share
tab, you can invite others to view or edit. Published mode allows
access to anyone. You can think of a published spreadsheet a public
copy of the live spreadsheet, where every time you publish it, the
live data is copied to the published data.

If a gadget references the live data, the current user needs to have
permissions to access the live data. If the gadget access the
published data, the sheet (or entire spreadsheet) must be published.

To access the published data of a spreadsheet, append to the url the
parameter pub=1. When you publish a gadget, you can see that this
parameter is appended to the data source url.

Prateek Agarwal

unread,
Mar 20, 2008, 7:08:48 AM3/20/08
to google-visua...@googlegroups.com
Thanks a lot VizGuy my problem is solved. Can this be added in Google FAQ because this I think would be quite a frequently asked question
--
my name is quark
coz i hav a sparq

minti

unread,
Mar 20, 2008, 3:47:50 PM3/20/08
to Google Visualization API
i m still getting the error as i add pub=1

here is source code

<html>
<title>noTitle</title>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></
script>


<script type="text/javascript">
google.load("visualization", "1");
function initialize()
{
var query = new google.visualization.Query("http://
spreadsheets.google.com/tq?key=py04yTuIPAKwa2d-zZp6Gbw&pub=1");
query.send(handleQueryResponse); // Send the query
with a callback function
}


google.setOnLoadCallback(initialize); // Set callback to run
when API is loaded


// Query response handler function.
function handleQueryResponse(response)
{
if (response.isError())
{ alert('Error in query: ' +
response.getMessage() + ' ' + response.getDetailedMessage());
return;
}


var data = response.getDataTable();
var html = [];


html.push('<table border="1">');
// Header row
html.push('<tr><th>Seq</th>');


for (var col = 0; col < data.getNumberOfColumns(); col+
+)
{ html.push('<th>' +
escapeHtml(data.getColumnLabel(col)) + '</th>');
}


html.push('</tr>');


for (var row = 0; row < data.getNumberOfRows(); row+
+)
{
html.push('<tr><td align="right">' + (row + 1)
+ '</td>');


for (var col = 0; col <
data.getNumberOfColumns(); col++)
{
html.push(data.getColumnType(col) ==
'number' ? '<td align="right">' : '<td>');

html.push(escapeHtml(data.getFormattedValue(row,col)));
html.push('</td>');
}


html.push('</tr>');
}


html.push('</table>');
document.getElementById('tablediv').innerHTML
= html.join('');
}


function escapeHtml(text)
{
if (text == null)
return '';


return text.replace(/&/g, '&amp;').replace(/</g,
'&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
</script>
</head>
<body>
<div id="tablediv">Loading...</div>
</body>
</html>




On Mar 20, 4:08 pm, "Prateek Agarwal" <agarwal.prat...@gmail.com>
wrote:
> coz i hav a sparq- Hide quoted text -
>
> - Show quoted text -

JR

unread,
Mar 20, 2008, 4:22:17 PM3/20/08
to Google Visualization API
Make sure your spreadsheet is actually published - From within the
spreadsheet editor, open the "publish" pane and make sure it is
already published, with either all sheets or the particular sheet you
are trying to access.

I haven't looked at the code you posted in detail, so others should
still respond if they see something else here...

VizGuy (Google)

unread,
Mar 23, 2008, 3:17:36 AM3/23/08
to Google Visualization API
I copies your code and it worked fine on both FF and IE. Can you give
more information on the error you have ?
Reply all
Reply to author
Forward
0 new messages