【发布时间】:2021-08-20 01:10:51
【问题描述】:
我正在尝试致电:
https://sheets.googleapis.com/v4/spreadsheets/GOOGLE_SHEET_ID:batchUpdate
如:
fetch(
`https://sheets.googleapis.com/v4/spreadsheets/GOOGLE_SHEET_ID:batchUpdate`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${bearerToken}`,
},
body: JSON.stringify({
requests: [
{
repeatCell: {
range: {
startColumnIndex: 0,
endColumnIndex: 1,
startRowIndex: 0,
endRowIndex: 1,
sheetId: 0,
},
cell: {
userEnteredValue: {
numberValue: 10,
},
},
fields: "*",
},
},
],
}),
}
);
我正在尝试使用 firebase auth 来获取不记名令牌,如下所示:
firebase.auth().onAuthStateChanged(user => {
if (user) {
user.getIdToken().then(token => setBearerToken(token))
}
});
问题是使用该令牌我得到了这个响应(是的,我检查了 bearerToken 是否设置正确):
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
Id Token 有效吗?如何从 Firebase Auth 获取适当的访问令牌?
【问题讨论】:
标签: javascript firebase google-sheets google-api