2

我只想将我的电子表格拉入应用程序/网站。理想情况下,我希望它是私有的,但首先我试图通过“对公众可用”和“发布到网络”的电子表格引入数据。

$.ajax({
   type: 'GET',
   url: 'http://spreadsheets.google.com/feeds/cells/' + spreadsheetKey + '/od6/public/full?alt=json',
   success: function(data){
     alert("success");
   } 
 });

这总是导致:

“您没有查看电子表格的权限。请确保您已通过适当的身份验证。”

我试过不带 ?alt=json,用“list”代替“cells”,用“values”代替“full”。没有任何效果。

另外,有没有办法将访问令牌传递给这个调用?我正在通过 Google 登录进行身份验证并允许电子表格 API 范围。我试过 &accessToken=xxx 和 &access_token=xxx。该文档没有任何关于 Javascript 的内容。

4

1 回答 1

2

For Javascript access to a private spreadsheet, you'll need the Javascript library here: https://code.google.com/p/google-api-javascript-client/wiki/Authentication That allows you to use OAuth2.0 which allows you to access a private Google Spreadsheet. See the answer under Google Spreadsheets API with OAuth 2.0 using Javascript for a full description.

For the access token, the syntax is: &access_token=xxx The relevant details for Javascript is under the Protocol heading in the Google Spreadsheet API, but it isn't that helpful I've found.

To get JSON do the following:

var url = 'https://spreadsheets.google.com/feeds/list/' + urlLocation + '/od6/private/full?alt=json-in-script&access_token=' + token + '&callback=?';
$.getJSON(url, function(data) {
    //do stuff with data here
});
于 2013-03-21T10:20:16.613 回答