HTTP Cloud函数和事件驱动的Cloud函数能否访问Firestore中的同一集合



我有一个事件驱动的云函数(用Node.js编写(,每当存储桶发生变化时,它就会在Firestore中创建video集合。但当我试图从HTTP函数访问相同的数据时,API抛出了一个401未经授权的错误。

HTTP功能:

exports.getVideos = (req, res) => {
db.collection('video').get().then(querySnapshot =>  {
return res.status(200).json({
videos: querySnapshot.docs.map(doc => doc.data()),
total: querySnapshot.size
});
})
.catch(error => {
functions.logger.error('Error getting video details: ', error);
return res.status(500).json({ error });
});
};

API回应:401未经授权的

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unauthorized</h1>
<h2>Your client does not have permission to the requested URL <code>/video/get-videos</code>.</h2>
<h2></h2>
</body>
</html>

我没有看到代码方面的任何问题,所以我想知道这是什么根本原因。

可能是使用不同的服务帐户执行不同的云功能。其中一个需要IAM角色/权限,另一个则不需要。

另一种选择——你能检查一下所有这些都发生在一个GCP项目中,并且两个云功能都应该与一个(相同的(firestore集合一起工作吗?

最新更新