Google APIs 學習/使用

1.應用場景

瞭解並使用Google APIs, 用於開發當中.

2.學習/操作

背景:

公司開發有用到Google APIs,所以只能去了解.

 

1.介紹

簡單說, 就是Google提供操作Google文檔的api,

方便在項目使用code進行操作.

 

2.操作

https://developers.google.com/apis-explorer  //Google APIs Explorer

https://developers.google.com/sheets/api/reference/rest  //在Google APIs Explorer, 搜索sheets之後的結果

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values  //REST Resource: spreadsheets.values

 

後續補充

...

3.問題/補充

1.如何使用api獲取Google Spreadsheet中的行數?

參考: https://stackoom.com/question/178iy/如何使用api獲取Google-Spreadsheet中的行數

 

查了文檔,以及Google搜索之後,發現只是支持Python進行查詢獲取rowCount

nodeJS解決辦法:

折中辦法,自行記錄rowCount,然後獲取.

async function updateRowsCount(sheets, spreadsheetId, sheetName){
    const res = await sheets.spreadsheets.values.update({
        spreadsheetId: spreadsheetId,
        range: `${sheetName}!${LastRowCountCell}`,
        valueInputOption: 'USER_ENTERED',
        requestBody: {
            values: [
                ['=COUNT(A:A)'],
            ],
        },
    })
    return res.data;
}

這種辦法,會每次更新rowCount,然後再查詢獲取rowCount值

 

優化:

應該繼續查詢文檔或者nodeJS組件,或者可以考慮自己試着去寫組件。//TBD

4.參考

https://github.com/googleapis/google-api-nodejs-client/#google-apis  //googleapis/google-api-nodejs-client

https://developers.google.com/apis-explorer  //Google APIs Explorer

https://stackoverflow.com/questions/61749543/how-to-get-the-correct-parameters-for-the-googleapi-nodejs-client //How to get the correct parameters for the googleapi-nodejs-client

後續補充

...

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章