我试图创建一个函数,将我的Appscript连接到Firebase数据库。
出于某种原因,它向我展示了:
下午2:29:44错误
类型错误:file.blob不是函数
getServiceAccountKey@firebase/firebase.gs:7
这是我的代码:
const CREDENTIALS_FILE_ID = "Your File ID";
const PROJECT_ID = "Project ID";
function getServiceAccountKey() {
var file = DriveApp.getFileById(CREDENTIALS_FILE_ID);
JSON.parse(file.blob().getDataAsString());
}
function testFunc(){
console.log(getServiceAccountKey());
}
function getAccessToken() {
var serviceAccount = getServiceAccountKey();
var tokenUrl = "https://www.googleapis.com/oauth2/v4/token";
var payload = {
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
assertion: createJWT(serviceAccount),
};
var options = {
method: "post",
payload: payload,
};
var response = UrlFetchApp.fetch(tokenUrl, options);
var token = JSON.parse(response.getContentText()).access_token;
return token;
}
我还尝试使用其他方法,例如
.stringify()
但仍然不起作用。