我调用了引用Deploy to your site using the Hosting REST API的Hosting API,但得到了以下响应:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
代码:
const { google } = require("googleapis");
var key = require('./service-account.json');
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
"https://www.googleapis.com/auth/firebase.hosting",
null
);
jwtClient.authorize(function(err, tokens) {
if (err) {
console.error(err);
return;
}
console.log(tokens.access_token);
});
Shell:
$ node main.js
ya29.c.Elp0...
$ curl -H "Content-Type: application/json" \
-H "Authorization: Bearer ya29.c.Elp0..." \
-d '{
"config": {
"headers": [{
"glob": "**",
"headers": {
"Cache-Control": "max-age=1800"
}
}]
}
}' \
https://firebasehosting.googleapis.com/v1beta1/sites/[project-id]/versions
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
service-account.json的项目ID和api端点中的项目ID相同。
另一方面,只有在使用releases.list方法时,我才能获得成功的响应:
$ curl -H "Authorization: Bearer ya29.c.Elp0..." \
https://firebasehosting.googleapis.com/v1beta1/sites/[project-id]/releases
{
"releases": [
...
]
}
有关如何解决此问题的任何提示?
谢谢。
范围错误。
在document中,授权范围是firebase.hosting,firebase和云平台之一,但是我只有在使用https://www.googleapis.com/auth/cloud-platform
时才能获得成功的响应。