我在谷歌云控制臺中創建了一個密鑰。我什至嘗試重新制作它并使用新的。

我試影像這樣使用它:
export const getSheet= async () => {
try {
const sheetId ='xxxxxxx'
const tabName = 'myTab'
const accountKey = 'xxxxxxx'
const url =' https://sheets.googleapis.com/v4/spreadsheets/' sheetId '/values/' tabName '?key=' accountKey
console.log(url)
const response = await fetch(url);
console.log(response);
return '';
} catch (error) {
console.log(error);
} finally {
console.log('finally');
}
};
發送的請求是:
https://sheets.googleapis.com/v4/spreadsheets/xxxxxxx/values/myTab?key=xxxxxxx
無論我做什么,我都會得到
error: {code: 403, message: "The caller does not have permission", status: "PERMISSION_DENIED"}
我已經參考了這些關于相同問題的堆疊溢位帖子,但沒有運氣
- Google 表格 API 上的錯誤 403
- 谷歌表格 API V4 403 錯誤
- 使用 apikey 從 Google Sheets API 獲取 403
有沒有人遇到過這個并能夠解決它?
謝謝-咖啡
uj5u.com熱心網友回復:
您不能使用 API 密鑰訪問 (Google Workplace) 用戶資料,例如作業表;如果作業表是公開的(任何知道鏈接的人),您可能(!?)只能使用 API 密鑰。
誠然,這些選項令人困惑,但是:
- API 密鑰對應用進行身份驗證
- OAuth 用于對用戶進行身份驗證
查看客戶端 Web 應用程式的身份驗證和授權以及OAuth 。
uj5u.com熱心網友回復:
您可以查看用于 OAuth 設定的 Sheets API 的 Javascript 快速入門指南。您可以使用Spreadsheet.values.get與提供的 URL 參考上的示例腳本類似的方法訪問作業表。
async function listMajors() {
let response;
try {
// Fetch first 10 files
response = await gapi.client.sheets.spreadsheets.values.get({
spreadsheetId: 'SHEETID',
range: 'SHEETRANGE',
});
} catch (err) {
document.getElementById('content').innerText = err.message;
return;
}
const range = response.result;
if (!range || !range.values || range.values.length == 0) {
document.getElementById('content').innerText = 'No values found.';
return;
}
就像 DazWilkin 提供的一樣。確保您的應用符合Google 的 OAuth2 政策。
您還可以先在瀏覽器上測驗您的請求 url,看看它是否回傳作業表資料的 JSON 回應。在公共作業表上測驗了這種https://sheets.googleapis.com/v4/spreadsheets/xxxxxxx/values/myTab?key=xxxxxxx格式,只要將作業表資料設定為“任何知道鏈接的人”,它就會回傳作業表資料
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/486527.html
標籤:javascript Vue.js 谷歌表格 谷歌API 谷歌表格 API
上一篇:GoogleSheetsAppScript-doPost中的嵌套trycatch-行為取決于呼叫方法?
下一篇:在Google表格中,從=now()中減去字串“YYYY-MM-DDHH:MM:SSET”。如何將字串轉換為數字?
