我们正在准备一个 firebase 触发器来处理 android 的实时开发者通知,我们必须使用 Google Play Developer API 来了解用户订阅的详细信息。因此,我们在 Google Play 控制台中关联了 firebase 服务帐户,并授予了必要的访问权限。
我们使用 google 的 nodejs 库用于 googleapis(github 链接)并编写了如下代码:
return google.auth.getClient({
keyFile: path.join(__dirname, './service-account.json'),
scope: 'https://www.googleapis.com/auth/androidpublisher'
}) .then((client) => {
const androidpublisher = google.androidpublisher({
version: 'v3',
auth: client
});
const params = {
packageName: ANDROID_PACKAGE_NAME,
subscriptionId: ANDROID_SUBSCRIPTIONID,
token: token
};
return androidpublisher.purchases.subscriptions.get(params)
.then(res => {
console.log(`The response is ${res.data}`);
return null;
})
.catch(error => {
console.error(error);
});
});
但它返回给我们一个错误状态:'无效的凭据',我对此有点迷茫。我已经使用带有授权令牌的 curl 对该 API 进行了测试,它也显示了 401 错误响应。
我不确定我上面的流程是否正确,有人可以给我任何建议吗?