[英]Use getIdToken as Authorization token for Google Sheet API
I am trying to make a call to: https://sheets.googleapis.com/v4/spreadsheets/GOOGLE_SHEET_ID:batchUpdate
我正在尝试致电:
https://sheets.googleapis.com/v4/spreadsheets/GOOGLE_SHEET_ID:batchUpdate
as in:如:
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: "*",
},
},
],
}),
}
);
I am trying to use firebase auth to get the bearer token as follows:我正在尝试使用 firebase auth 来获取不记名令牌,如下所示:
firebase.auth().onAuthStateChanged(user => {
if (user) {
user.getIdToken().then(token => setBearerToken(token))
}
});
The problem is that using that token I get this response (yes I checked that the bearerToken is properly set):问题是使用该令牌我得到了这个响应(是的,我检查了 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"
}
}
Is the Id Token valid? Id Token 有效吗? How can I get the appropiate Access Token from Firebase Auth?
如何从 Firebase Auth 获取适当的访问令牌?
If you want to call the google sheets API, then you need to get access token from the Google Authorization server.如果你想调用谷歌表格 API,那么你需要从谷歌授权服务器获取访问令牌。 Is firebase indirectly getting the bearer token from the Google Authorization server?
firebase 是否间接从 Google 授权服务器获取不记名令牌? Secondly, bearer token and ID token are two separate concepts.
其次,不记名令牌和身份令牌是两个独立的概念。 Oauth ID Token is used to get information about User but access token can be passed to Resource API.
Oauth ID 令牌用于获取有关用户的信息,但访问令牌可以传递给资源 API。 I suspect that you are passing a totally unrelated token to the API.
我怀疑您正在将一个完全不相关的令牌传递给 API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.