在Google Cloud Prediction for NodeJS API库中验证服务帐户凭证失败



我正在使用googleapis库,并使用JWT成功验证了我的服务帐户凭据。然后我发现google-cloud库,它有预测API的特定模块,但未能验证相同的服务帐户凭据。

我不使用谷歌计算引擎或应用程序引擎,并在本地开发工作

我遵循文档中的代码:

var key = require('./MY_SERVICE_ACCOUNT_CREDENTIALS.json')
var prediction = require('@google-cloud/prediction')({
  projectId: 'MY_PROJECT_ID',
  credentials: key
})
prediction.getModels((err, models) => {
  if (err) {
    console.log(err)
    return
  }
  console.log('Models:', models)
})

返回:

{ ApiError: Access to project denied: user requires read permissions.                                              
    at [here goes stack trace]                                                                                   
  code: 401,                                                                                                       
  errors:                                                                                                          
   [ { domain: 'global',                                                                                           
       reason: 'authError',                                                                                        
       message: 'Access to project denied: user requires read permissions.',                                       
       locationType: 'header',                                                                                     
       location: 'Authorization' } ],                                                                              
  response: undefined,                                                                                             
  message: 'Access to project denied: user requires read permissions.' } 

我不知道哪里出了问题,我不确定我是否需要与googleapis进行认证,并将其与google-cloud或等集成。也是缺少样本

我知道这是几个月前的错误,但这个错误是不言自明的,但我自己也遇到了这个问题。

从本质上讲,您的服务密钥没有被赋予适当的权限,以便从您的项目中读取(或写入)信息。在IAM下查找您的服务帐户在Google Cloud Console中的Admin,并将Project→Editor和/或Project→Viewer添加到您创建的服务帐户。在添加了这些权限后,请确保按下"保存"键,并等待大约20秒让这些权限反映出来。

最新更新