我正在尝试呼叫: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令牌有效吗?如何从Firebase Auth获取适当的访问令牌?
发布于 2021-06-04 05:56:57
如果您想调用google sheets API,那么您需要从Google Authorization服务器获取访问令牌。firebase是否间接从Google Authorization服务器获取持有者令牌?其次,持有者令牌和身份令牌是两个独立的概念。Oauth ID令牌用于获取有关用户的信息,但访问令牌可以传递给资源API。我怀疑您正在向API传递一个完全不相关的令牌。
https://stackoverflow.com/questions/67795577
复制相似问题