2

我只想將我的電子表格放入應用程序/網站。理想情況下,我希望它是私人的,但首先我試圖通過電子表格「向公衆提供」和「發佈到網絡」中引入數據。通過Google Spreadsheet API導入JSON

$.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登錄進行身份驗證,並允許使用Spreadsheet API範圍。我試過& accessToken = xxx和& access_token = xxx。該文檔沒有任何Javascript的。

回答

2

對於使用Javascript訪問私人電子表格,您需要在此處使用Javascript庫:https://code.google.com/p/google-api-javascript-client/wiki/Authentication允許您使用OAuth2.0來訪問私人Google電子表格。有關完整說明,請參閱Google Spreadsheets API with OAuth 2.0 using Javascript下的答案。

對於訪問令牌,其語法爲: &access_token=xxx JavaScript的相關詳細信息在Google Spreadsheet API的協議標題下,但它對我找不到幫助。

要獲得JSON做到以下幾點:

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 
});